[Java for Android App Development] Saurabh Shah:
A splash screen is an image that appears while a game or program is loading. Splash screen can be used to show app / company logo for a couple of second.

In this GUIDE we are going to learn how to implement splash screen in your android application.

I have created a application with name com.example.assassin.splash.screen.test

Browse through res/drawable-hdpi and paste a png image into the folder.

[Note: Image used in this guide is with name = splash.png , height=800 , width=480]

Now browse to res/layout folder and create a splash activity.

To create a splash activity Right click on layout folder and select New>Other>Android>Android XML File

And create a file called splash

Having problem? See the snapshots.

ScreenShot

​

Now open your splash.xml file and paste the following codes.

[B]<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/splash"
>
</LinearLayout>[/B]

Save it.

Browse to src/com.example.assassin.splash.screen.test and create a new class name Splash

ScreenShot

​

Code for Splash.java

package com.example.assassin.splash.screen.test;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class Splash extends Activity{
@Override
protected void onCreate(Bundle assassin) {
// TODO Auto-generated method stub
super.onCreate(assassin);
setContentView(R.layout.splash);

Thread timer = new Thread(){
public void run(){
try{
sleep(5000); //time to display splash screen in millisecond

}
catch (InterruptedException e){
e.printStackTrace();

}
finally{
Intent openStartingPoint = new Intent("com.example.assassin.splash.screen.STARTINGPOINT");
startActivity(openStartingPoint);
}
}
};
timer.start();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
}

Save It.

ScreenShot

Now open AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.assassin.splash.screen.test"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >

<activity
android:name=".Splash"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name="com.example.assassin.splash.screen.test.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.assassin.splash.screen.STARTINGPOINT" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

</application>

</manifest>

Save It.

ScreenShot

​

Well now you have successfully created a splash sceen activity for your application.

Designing MainActivity.xml is up to you. :p

MainActivity.xml used in this guide looks like this:

ScreenShot

​

Please correct me if the code goes wrong somewhere.

Saurabh Shah