arj
arj

Reputation: 5

How to set delay between main activity and a new activity

I want a welcome screen to appear and then after a delay of few seconds start a new activity. Ex. I have mainactivity.java and second activity.java. main activity displays a welcome message and second activity does work. I am using intent to start second activity from main. But the main does not start instead directly second is loaded. Help!!!

Upvotes: 0

Views: 3150

Answers (4)

Guy
Guy

Reputation: 6522

Are you talking about a splash screen? Try this tutorial, it should get you exactly what you want.

Upvotes: 0

Chinmoy Debnath
Chinmoy Debnath

Reputation: 2824

use handler to do that for example

private Handler handler;
private Runnable delayRunnable;

handler = new Handler();
delayRunnable = new Runnable() {

     @Override
     public void run() {
    // TODO Auto-generated method stub  

           Add your intent here for Second Activity
           Intent i = new Intent(getApplicationContext(), secondactivity.class);
             startActivity(i);
    }
};      
handler.postDelayed(delayRunnable, 3000);

Upvotes: 1

Scott Helme
Scott Helme

Reputation: 4799

Try:

private Handler handler = new Handler();

handler.postAtTime(splashTimeTask, SystemClock.uptimeMillis() + 500);

private Runnable splashTimeTask = new Runnable() {
    public void run() {

   }
};

Upvotes: 0

Yukai
Yukai

Reputation: 43

You can use Splash screen activity replacing your mainactivity, and your secondactivity would be the mainactivity of your app...here's a simple tutorial on how to make a splash screen.

Upvotes: 0

Related Questions