Android Splash Screen Tutorial

In this tutorial, you will learn how to implement a Splash Screen in your Android application. Showing a splash screen is a common feature of many applications, it shows off your logo or maybe just a loading screen to the user before your application launches. We will create a splash screen without the title bar, then set a timer duration and prevent the user’s back button from returning them to the splash screen. So lets begin…

Create a new project in Eclipse File > New > Android Application Project. Fill in the details and name your project SplashTutorial.

Application Name : SplashTutorial

Project Name : SplashTutorial

Package Name : com.androidbegin.splashtutorial

Open your MainActivity.java and paste the following code.

MainActivity.java

package com.androidbegin.splashtutorial;

import android.os.Bundle;
import android.app.Activity;

public class MainActivity extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// Get the view from activity_main.xml
		setContentView(R.layout.activity_main);
	}

}

Next, create an XML file for the MainActivity graphical layout. Go to res > layout > Right Click on layout > New > Android XML File

Name your new XML file activity_main.xml and paste the following code.

activity_main.xml 



    

Next, create a new activity for the splash screen. Go to File > New > Class and name it SplashScreenActivity.java. Select your package named com.androidbegin.splashtutorial and click Finish.

Open your SplashScreenActivity.java and paste the following code.

SplashScreenActivity.java

package com.androidbegin.splashtutorial;

import java.util.Timer;
import java.util.TimerTask;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Window;

public class SplashScreenActivity extends Activity {

	// Set Duration of the Splash Screen
	long Delay = 8000;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// Remove the Title Bar
		requestWindowFeature(Window.FEATURE_NO_TITLE);

		// Get the view from splash_screen.xml
		setContentView(R.layout.splash_screen);

		// Create a Timer
		Timer RunSplash = new Timer();

		// Task to do when the timer ends
		TimerTask ShowSplash = new TimerTask() {
			@Override
			public void run() {
				// Close SplashScreenActivity.class
				finish();

				// Start MainActivity.class
				Intent myIntent = new Intent(SplashScreenActivity.this,
						MainActivity.class);
				startActivity(myIntent);
			}
		};

		// Start the timer
		RunSplash.schedule(ShowSplash, Delay);
	}
}

We have created a timer with the delay of 8000 milliseconds before the splash screen ends. The TimerTask will start when the timer ends.

Next, create an XML file for the Splash Screen graphical layout. Go to res > layout > Right Click on layout > New > Android XML File

Name your new XML file splash_screen.xml and paste the following code.

splash_screen.xml



    

    
    

For this tutorial, we have prepared a sample logo for the splash screen. Insert the sample logo into your res drawable-hdpi.

Sample Logo

[wpfilebase tag=file id=30 tpl=download-button /]

Next, change the application name and texts. Open your strings.xml in your res > values folder and paste the following code.
strings.xml



    SplashScreen Tutorial
    Main Page from MainActivity.java

In your AndroidManifest.xml, we need to declare the SplashScreenActivity together with the intent filter to force this activity to run when the application launches. Then declare an activity for MainActivity.java. Open your AndroidManifest.xml and paste the following code.

AndroidManifest.xml



    

    
        
            
                

                
            
        
        
        
    

Output :

SplashScreen Tutorial ScreenShots

Source Code 

[purchase_link id=”7874″ text=”Purchase to Download Source Code” style=”button” color=”green”]

Latest comments

nice demo

Discussion Board

Android Splash Screen Tutorial

Can we use handler instead of timer?

Fenil Shah

Android Splash Screen Tutorial

Your welcome Albert, glad it helped. :)

AndroidBegin

Android Splash Screen Tutorial

I made it work using a videoview, it works quite well. Thanks a lot for your tutorial and help!

Albert John Mwanjesa

Android Splash Screen Tutorial