1

I would like to create a splash screen for an app I hope to make. My first solution was to display a new layout for a few seconds and then display a new layout like so:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.logo)
    android.os.SystemClock.sleep(5000);
    setContentView(R.layout.activity_main);
}

But the problem is that it displays a white screen for 5 seconds then goes to my main screen. I Thought I could tackle this problem by creating a new method or class and change the layout from there but using a method did nothing and creating a class only proved to be more difficult because I'm pretty sure I'd have to use AsyncTask. I feel like there is a very easy solution I don't know about. Thanks in advance, Mr. Schmuck

MrSchmuck
  • 55
  • 10
  • not the correct way to achieve what you are looking for...atleast search before posting there are so many threads about this on so – karan May 21 '16 at 04:15
  • 3
    Possible duplicate of [How do I make a splash screen?](http://stackoverflow.com/questions/5486789/how-do-i-make-a-splash-screen) – Daniel May 21 '16 at 04:15

1 Answers1

0

you need to create another activity for splash screen

Example:

public class SplashScreen extends Activity {

    // Splash screen timer
    private static int SPLASH_TIME_OUT = 3000;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        new Handler().postDelayed(new Runnable() {  
            @Override
            public void run() {
                // This method will be executed once the timer is over
                // Start your app main activity
                Intent i = new Intent(SplashScreen.this, MainActivity.class);
                startActivity(i);

                // close this activity
                finish();
            }
        }, SPLASH_TIME_OUT);
    }

}

Here is the full example

Hope it helps

Atiq
  • 14,435
  • 6
  • 54
  • 69
  • Thanks for your quick reply! I gave it a try but it gave me an error at "new Handler()". It said that it was abstract and could not be instantiated. – MrSchmuck May 21 '16 at 04:40