0

my splash screen

/**
 * Created by HumzaYunas on 05/01/2016.
 */
import android.app.Activity;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class splashscreen extends Activity {
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        Window window = getWindow();
        window.setFormat(PixelFormat.RGBA_8888);
    }
    /** Called when the activity is first created. */
    Thread splashTread;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splashscreen);
        StartAnimations();
    }
    private void StartAnimations() {
        Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha);
        anim.reset();
        LinearLayout l=(LinearLayout) findViewById(R.id.lin_lay);
        l.clearAnimation();
        l.startAnimation(anim);

        anim = AnimationUtils.loadAnimation(this, R.anim.translate);
        anim.reset();
        ImageView iv = (ImageView) findViewById(R.id.splash);
        iv.clearAnimation();
        iv.startAnimation(anim);

        splashTread = new Thread() {
            @Override
            public void run() {
                try {
                    int waited = 0;
                    // Splash screen pause time
                    while (waited < 5000) {
                        sleep(100);
                        waited += 100;
                    }
                    Intent intent = new Intent(splashscreen.this,
                            MainActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                    startActivity(intent);
                    splashscreen.this.finish();
                } catch (InterruptedException e) {
                    // do nothing
                } finally {
                    splashscreen.this.finish();
                }

            }
        };
        splashTread.start();

    }

}

and this is taking much time as far as i think so :( ...... I'm just curious that how to load app like facebook that as we tap on fb icon and the app loads blazing fast and splash screen is shown but in my app i'm having this problem. Any help will be appreciated :) ..

My androidmanifest here

<uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar">
        <activity android:name=".splashscreen"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".MainActivity">
        </activity>
        <activity
            android:name=".ShowPosts"
            android:label="@string/posttitle"
            android:parentActivityName=".MainActivity"/>
        <activity android:name=".LiveScores" />
    </application>

I just made my splash screen as main activity because i wanna load my app fast so that splash screen take time and then after that my mainactivity get some time to work and load

Humza Malik
  • 343
  • 3
  • 14

1 Answers1

1

you can read more here: Add splash in application

if you want also to create an animation between the screens, see transitions between activities:

transitions between activities

Community
  • 1
  • 1
visionix visionix
  • 780
  • 1
  • 8
  • 18
  • Actually i'm talking about my app starting delay . It's taking long time to show even splash screen . This is the issue :( – Humza Malik May 01 '16 at 11:22
  • I will recommend you to read how to do it properly(in the links I provided), also you don't have to use a thread just do it with postDelay( new Runnable(), delayInMillis) – visionix visionix May 01 '16 at 11:33
  • I've followed what in the links but still somehow same time it's taking and i'm sorry actually i'm beginner so that's why i don't understand what the factors and how these things are working :) – Humza Malik May 01 '16 at 18:47