Splash Screen Demo App for Android

Recently I wrote a blog article on splash screens for Android apps. I didn’t take the time then to build a simple demo app with source code so I’m doing so now.

There is not really much to my Splash Demo app. I took the basic Hello world app and added a splash screen. The splash screen stays visible for about 5 seconds and then switches to the Hello activity. The app looks like the following:


Source Code

Download the source code for the Eclipse project from this page at wglxy.com:


If you find that the app does not build in Eclipse, be sure to do a clean build by using the “Clean” item on the Project menu. The project was built with Android 2.2.

Building the Demo

Here are steps I took to build this demo app.

  • I started with the default Android project that displays “hello”.
  • I added a LauncherActivity and changed the Android manifest file to start that activity rather than the MainActivity.
  • I built an image, 512 x 512, to use as the splash image.
  • I added a layout xml file for LauncherActivity that displays the image on a black background.
  • I changed the onCreate method of the LauncherActivity so it displays its view for 5 seconds and then starts the MainActivity.
  • I added an AsyncTask class as an internal class of LauncherActivity in order to have a background task triggering the transition to the MainActivity.

The last two steps require a bit more explanation.

The onCreate method of LauncherActivity is the place where the transition to the main activity happens. It does two things. It sets up to handle clicks on the image view showing the splash image. That provides a user with a quick way to skip the splash screen. The second thing onCreate does is start a second task. The GoHomeAfterDelay class is a subclass of AsyncTask. It runs in the background, or, in this case, it sleeps in the background. When it awakes, the task finishes and triggers a call to start the main activity. Note also that I put the actual time of delay, 5000 milliseconds, in a values.xml resource file as the integer named splash_screen_time.

protected void onCreate(Bundle savedInstanceState)

 // Set up to go to the home screen if a user touches the image.
 ImageView i1 = (ImageView) findViewById (R.id.splash_image);
 if (i1 != null) i1.setOnClickListener(this);

 // Set up to go to the home screen after a short delay.
 int delay = getResources ().getInteger (R.integer.splash_screen_time);
 mDelayTask = new GoHomeAfterDelay (this);
 mDelayTask.execute (delay);

The GoHomeAfterDelay class is a subclass of AsyncTask. Its definition is at the bottom of the LauncherActivity.java file. GoHomeAfterDelay’s doInBackground method does nothing more than go to sleep for the time specified. Part of the protocol for any AsyncTask involves executing its onPostExecute method when the task completes. So that’s the spot where we end the launcher activity and start the main activity.

 * Perform the task, which is to wait N milliseconds.
 * Return 1 if the wait completed or 0 if the task was cancelled.
@Override protected Integer doInBackground(Integer... delayValues)
   int delay = delayValues [0];
   try {
     Thread.sleep (delay);
   } catch (InterruptedException ex) {} if (isCancelled ()) return 0;
   else return 1;
 * Report that the task has finished.
 * This method runs in the UI thread.
@Override protected void onPostExecute (Integer moveCount)
  if (! mCancelled) {
     if (mActivity != null) mActivity.goHome (true);
  mActivity.mDelayTask = null;

If you are unfamiliar with AsyncTask and the reason for it, I refer you to two earlier blog notes:  AsyncTask note , Long Computations note.

The place where MainActivity is actually started is in the goHome method. It uses an Intent to start the activity. After that, there is a call to the finish method. That’s what stops the LauncherActivity and keeps it from showing up again when you hit the Back button.
public void goHome (boolean doFinish)
  final Intent intent = new Intent(this, MainActivity.class);
  intent.setFlags (Intent.FLAG_ACTIVITY_CLEAR_TOP);
  this.startActivity (intent);
  if (doFinish) finish ();


As I said earlier, there are several good articles about splash screens already out there. My favorite is the one on “Android Splash Screens Done Right“. Thanks go to Mr. Clifton for sharing this very useful information.

About Bill Lahti

Bill Lahti is an indie game developer. He is currently working on Lifeforms, a two-player game based on Conway’s Game of Life. Other iOS and Android games: Double Star II, Wing Leader, Gomoku League.
This entry was posted in Android and tagged , , . Bookmark the permalink.

4 Responses to Splash Screen Demo App for Android

  1. Ben says:

    Thanks a lot for this. I will be using it on the next version of our android guitar tuner app as the sounds are loading up.

    Great Stuff!

  2. Pingback: Splash Screen Demo With Sound « More Is Not Always Better

  3. jayson may says:

    whats the first thing I need to do too build a splash screen for my zte.

    • blahti says:

      I like to think about what first impression you want to leave with the user and then try to come up with several candidate images for a splash screen.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.