Free Shipping

Secure Payment

easy returns

24/7 support

  • Home
  • Blog
  • How to Create Splash Screen in Android

How to Create Splash Screen in Android

 July 9  | 0 Comments

Introduction
A Splash screen is a graphical control element consisting of a window containing an image, a logo and the current version of the software. A splash screen usually appears while a game or program is launching. @source wiki
The splash screen is an activity that will show for a specific time mentioned when your app is starting and after that specific time period redirect to application main screen.
There are some steps to create a splash screen.
1. Create a Drawable folder and import an image for your splash screen.
2. Adding an activity that will be used for splash screen in Android Application.

Class Description
Handler A Handler allows you to send and process Message and Runnable objects associated with the Activity.

 

Get Skilled in Android Development
Method Description
postDelayed(){..} Causes the Runnable interface to be added to the message queue, to be run after the specified amount of time elapses.
run(){..} This Handler method is used when your splash activity is running.
finish(){..} This method executed when particular handler time is finished.

Steps to Create a Splash Application:
1. Create a new project File > New > New Project and give an application name as “SplashDemo”.

 

 

2.Create a new XML file named as “splash.xml” and add a code for your splash screen.

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

3. Add a new Activity named as “Splash.java” and add a code for Handler for creating Splash Activity.
Add the code in onCreate(){..}

new Handler().postDelayed(new Runnable() {
    // Using handler with postDelayed called runnable run method
    @Override
    public void run() {
        Intent i = new Intent(Splash.this, MainActivity.class);
        startActivity(i);
        // close this activity
        finish();
    }
}, 5*1000); // wait for 5 seconds

4. In AndroidManifest.java, Add a Splash activity as a Main Launcher Activity and Add Other activity (MainActivity.java) like below:

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".Splash">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".MainActivity"></activity>
</application>

5. Run Your Application and You will get an output like this:
This screen will be displayed for 5 seconds and then automatically another screen comes up.

Download Project Link: https://github.com/hiteshbpatel/Android_Projects/tree/master/SplashDemo

>