Download Code

Android Splash Screen Example

In android splash screen example you will learn how to create splash screen using Thread in android application.More practical detail you visit this tutorial.First i’ll tell you about splash screen then we will go with thread to run it for some time and then start home screen.

Splash Screen

It’s an activity which set for some time and after some time it redirects to home/main activity.

Now let’s talk about splash screen sizes.We have to develop an application that support maximum devices.

LDPI

  • Portrait: 200×320 px
  • Landscape: 320×200 px

MDPI

  • Portrait: 320×480 px
  • Landscape: 480×320 px

HDPI

  • Portrait: 480×800 px
  • Landscape: 800×480 px

XHDPI

  • Portrait: 720×1280 px
  • Landscape: 1280×720 px

XXHDPI

  • Portrait: 960×1600 px
  • Landscape: 1600×960 px

XXXHDPI

  • Portrait: 1280×1920 px
  • Landscape: 1920×1280 px

These are screen densities to support our application.Now go ahead and create images in Photoshop just like me i have taken an example of this application.android splash screen,android splash screen example,splash screen example,splash screen,

Ok i am done with images.Now go ahead and create android application project.

android splash screen,android splash screen example,splash screen example,splash screen,

Next drop splash screen images in their respective directory just like this.Remember one thing that every image should have same name.

 

android splash screen,android splash screen example,splash screen example,splash screen,

Then go to activity_main.xml file and drag,drop image view and set image src to splash.This xml contains also padding of layout you can remove to fit full screen.

android splash screen,android splash screen example,splash screen example,splash screen,

Now go to MainActivity.java class.Create thread variable and set window/layout which display in application to full screen.Create new activity and layout which we will call home screen/activity also declare in Android Manifest .xml.

Put exception handling in run method of thread.Start Thread.

Home.XML

android splash screen,android splash screen example,splash screen example,splash screen,

Home.java

package androidcodec.splashscreen;

/*
 * 
 * All Rights Reserved By: Farhan Rasheed
 * 
 * */

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

public class home extends Activity{

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.home);
	}

}

MainActivity.java

package androidcodec.splashscreen;

/*
 * 
 * All Rights Reserved By: Farhan Rasheed
 * 
 * */

import android.support.v7.app.ActionBarActivity;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;


public class MainActivity extends Activity {

	Thread basicThread;  // thread variable
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE); // setting no title of window
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); // width and height of window using window manager
		setContentView(R.layout.activity_main);


		basicThread = new Thread(){
			// overriding run method
			public void run(){
				// try block
				try{
					sleep(10000);    // sleeping for 5 second

				}
				// catch block
				catch(InterruptedException e){
					e.printStackTrace();
				}
				// finally block it's optional
				finally{

					Intent n = new Intent(getApplicationContext(),home.class);
					startActivity(n);
					finish();
				}
			}
		};
		//starting the threads
		basicThread.start();

	}

}

Now run android splash screen example application.

android splash screen,android splash screen example,splash screen example,splash screen,

That’s it for this tutorial.

Thanks.