Create a splash screen for android app

0
452

To create a splash screen you need to create first a new layout splash.xml or anything you like to call and you customize you layout 

for my app i used this splash screen 

After that create a new java class (i call it splash too ^^)

Now Add this code to your class

package com.xochn.app;import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;public class splash extends Activity {
private boolean mIsBackButtonPressed;
private static final int SPLASH_DURATION =1500;

public void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Handler handler = new Handler();

HANDLER.POSTDELAYED(NEW RUNNABLE() {
@OVERRIDE
PUBLIC VOID RUN() {
FINISH();
IF (!MISBACKBUTTONPRESSED) {
INTENT INTENT = NEW INTENT(SPLASH.THIS, MAINACTIVITY.CLASS);
SPLASH.THIS.STARTACTIVITY(INTENT);
}
}
}, SPLASH_DURATION);
}

@OVERRIDE
PUBLIC VOID ONBACKPRESSED() {
MISBACKBUTTONPRESSED = TRUE;
SUPER.ONBACKPRESSED();
}

}

1500 is the duration of your splash screen R.layout.splash is the layout i create for my splashMainActivity.class is the class will be open after the display of splash.xml 

and the last step you have to change androidmanifest.xml

 <?xml version=”1.0″ encoding=”utf-8″?>
<manifest xmlns:android=”http://schemas.android.com/apk/res/android”
    package=”com.xochn.birthdayfacts” >

    <application
        android:allowBackup=”true”
        android:icon=”@drawable/ic_launcher”
        android:label=”@string/app_name”
        android:theme=”@style/AppTheme” >
        <activity
            android:name=”com.xochn.app.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=”.MainActivity”
            android:label=”@string/app_name” >
            <intent-filter>
                <action android:name=”android.intent.action.MAIN” />
                <category android:name=”android.intent.category.DEFAULT” />
            </intent-filter>
        </activity>

    </application>

</manifest>