How to add a splashscreen to Android applications

In this post I’m showing you how to add a simple splash screen to you application / game.

You need the splashscreen file, a layout file and to modifiy AndroidManifest.xml accordinly.  All this will be provided here.

I’m assuming that your main activity is named MainActivity.java.

The splashscreen is showed in the listing bellow. Change the package name according to your own structure (see lines 1, 3 and 4).

On line 21 you can see I’m calling a layout named splash.xml.

Listing 1 – Splashcreen.java

The splash.xml layout file is on listing 2. It must be in the res/layout folder under you project.

Listing 2 – splash.xml layout file.

Notice that line 21 references a file named splah. It’s the name of your image used in the splash screen. Be sure to add it under res/drawabe folder. I recommend you using a .png file.

Note: you should add other versions of splash.png file to other drawable folders to contemplate other screen resolutions (drawable-hdpi, drawable-ldpi, drawable-mdpi).

The next step need in ordr to show the splash screen and after some seconds () call the main activity is to change the AndroiManifest.xml file.

Listing 3 shows the needed code you have to add.

Listing 3 – AndroidManifest.xml

Pay attention to line 1 in listing 3. You must change the package name to matche yours.

And that’s it.

I hope it help you.

 

Please, try my games, play free on-line games on my site, tweet this post url and share it on facebook, google+ and other social medias.

This entry was posted in android, development and tagged , . Bookmark the permalink.
  • Thomas Bull

    Thanks for this great tutorial. Nice, straight forward and to the point.

    one question though…

    having successfully incorporated this into my game (i added a new class SplashScreenActivity, a splash.xml in layout and made additions to the manifest) after running i get 2 apks installed, one with the splash and one without. if i merge the content of SplashScreenActivity i still get 2 apks the one that did have the splash crashes, and the one without runs fine.

    hope you can shed some light on this

    tom

    • Thomas Bull

      cracked it… i had left the original LAUNCHER in the manifest. without that i get one functioning apk – with a splash screen

      thanks again for the tutorial

      Tom