-2

How do I call an activity from my splash screen using threads. just guide me in java code i.e how do i create a thread and call my next activity.

Amit
  • 13,134
  • 17
  • 77
  • 148

1 Answers1

1

If you want to display the second activity from your SplashActivity : Note: SplashActivity will be the Startup Activity in manafist

<activity android:name=".SplashActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

protected boolean _active = true;
protected int _splashTime = 5000;

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);    
    Thread splashTread = new Thread() {
            @Override
            public void run() {
                try {
                    int waited = 0;
                    while(_active && (waited < _splashTime)) {
                        sleep(100);
                        if(_active) {
                            waited += 100;
                        }
                    }
                } catch(InterruptedException e) {
                    // do nothing
                } finally {
                    finish();
                    startActivity(new Intent("com.package.AppName.SecondActivity"));
                }
            }
        };
        splashTread.start();
}

hope this will help you.

Basbous
  • 3,927
  • 4
  • 34
  • 62