0

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!!!

arj
  • 5
  • 1
  • 4

4 Answers4

1

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);
Chinmoy Debnath
  • 2,814
  • 16
  • 20
0

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.

Community
  • 1
  • 1
Yukai
  • 43
  • 9
0

Try:

private Handler handler = new Handler();

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

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

   }
};
Scott Helme
  • 4,786
  • 2
  • 23
  • 35
  • Intent i =new Intent(this,second.class) shows error in run method The constructor Intent(new Runnable(){}, Class) is undefined – arj Jul 21 '13 at 15:13
  • @arj Intent(FirstClass.this, second.class) should be ok – M G Jul 21 '13 at 15:18
0

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

Guy
  • 6,414
  • 19
  • 66
  • 136