Android

Android splash screen

There is 2 ways (at least) to create a splash screen :

The first is to create a splash activity displaying a layout and then transfert the user to the main activity. Here the SplashActivity.java :

Note : the splash screen is displayed during 2 seconds (2000 ms) before going to the main activity. You can tune the SPLASH_DURATION constant to change the duration.

In res/layout/splash_activity.xml you will have something like this :

You will put the image to display in res/drawable/splash_screen.png

And that’s all. The advantage of this method is that you can have exactly the layout you want. The drawback is that it does not appear instantly : you will have to wait half a second.

If you have just a small logo to display, the best wait is… NOT display layout, instead, you just have to add a theme to your AndroidManifest.xml :

res/values/styles.xml will be like this :

The picture will be defined in res/drawable/background_splash.xml :

You will put the image to display in res/drawable/splash_screen.png

and the background color in res/values/colors.xml :

And the most important to have the splash screen to be instantly displayed is to NOT display the layout, here I just commented out the layout setting inĀ SplashActivity.java :