EliasMP EliasMP - 1 year ago 79
Android Question

Coding a Splash Screen

I´m trying to made an app which shows a first layout for 5 seconds and after going to the index layout (Home).
The first layout shows only a logo and the name of the app...

protected void onCreate(Bundle savedInstanceState) {
Intent i = new Intent(this, Home.class);

If I comment the
SystemClock.sleep(5000); Intent i = new Intent(this, Home.class); startActivity(i);
, app works as I expected. Show the first layout, staying in this layout (obviously, I´m not launching anything else :P). But, If I descomment them, the activity wait for 5 seconds without showing anything (blank layout).

Any ideas?

Thanks guys.

Answer Source

In order to show a splash screen on your app you should not show a layout, try to put the main thread to sleep for 5 seconds and the wake the app again. The "right" way (there's no right way of showing a splash screen, as splash screens are almost forbidden on mobile apps) of showing a splash screen would be create a new Activity or Fragment that holds this screen and, using a Handler.postDelayed inside this activity, wait for 5 seconds and then show your main activity.

Useful information on Splash Screens:


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download