Android Splash Screen Tutorial

Android splash screen is used so that apps can show their brand icons before showing the content of app. This may also used to do some background work in  your application like loading resources from network while the splash screen is being shown. This will look smooth for user.

Unfortunately in android we don’t have any inbuilt mechanism to show splash screen compared to iOS. In this tutorial we are going to learn how to implement splash screen in your android application.

[su_note note_color=”#18DAA3″ text_color=”#000000″ radius=”0″]Our new Tutorial on how to add video in splash screen[/su_note]
When to use splash screen :
  1. To show your brand logo user.
  2. To load data from network or other source while showing splash screen.

We will be covering first scenario in this tutorial. One is showing splash screen using a timer.

 

[su_button url=”https://github.com/androidsrc/SimpleSplashScreen” target=”blank” style=”stroked” background=”#51d461″ color=”#ffffff” size=”6″ center=”yes” radius=”0″ icon=”icon: arrow-circle-o-down”]Download Full Source Code[/su_button]

 

Preview :

[su_youtube url=”http://youtu.be/FJ1HcshCtQE”]

Logic :

There is nothing magical in this case. We will create two activities , say MainActivity and SplashActivity. Now we will make SplashActivity as "android.intent.category.LAUNCHER" so that its icon is visible on launcher. When user will click application icon on launcher then the SplashActivity will be called and it will show some UI and after that it will launch the MainActivity .

So let’s get started by creating a new project

 Android Splash Screen Using Timer

1. Create a new project in Eclipse by navigating to File ⇒ New Android ⇒ Application Project and fill required details.

2. For Splash Screen we are creating a separate activity. Create a new class in your package and name it as SplashActivity.java

3. Now open AndroidManifest.xml update to following :

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

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="21" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >

        <!-- SplashActivity -->
        <activity
            android:name="com.example.splash.SplashActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.Black.NoTitleBar" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        <!-- MainActivity -->
        <activity
            android:name="com.example.splash.MainActivity"
            android:label="@string/app_name" >
        </activity>
    </application>

</manifest>

4. Create file activity_splash.xml in res => layout and copy following code.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#37474f" >

    <ImageView
        android:id="@+id/imgLogo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:src="@drawable/logo" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="100dp"
        android:gravity="center_horizontal"
        android:text="www.androidSRC.net"
        android:textColor="#ffa000"
        android:textSize="25sp" />

</RelativeLayout>

5.  Now add following code to SplashActivity.java

package com.example.splash;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

public class SplashActivity extends Activity {

    // Splash screen timer
    private static int SPLASH_TIME_OUT = 3000;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        new Handler().postDelayed(new Runnable() {

			/*
             * Showing splash screen with a timer. This will be useful when you
			 * want to show case your app logo / company
			 */

            @Override
            public void run() {
                // This method will be executed once the timer is over
                // Start your app main activity
                Intent i = new Intent(SplashActivity.this, MainActivity.class);
                startActivity(i);

                // close this activity
                finish();
            }
        }, SPLASH_TIME_OUT);
    }
}

6.  Now build and run the project. You will see splash screen for 3 second and then the main activity.

GuRu

Technology enthusiast. Loves to tinker with things. Always trying to create something wonderful using technology. Loves coding for Android, Raspberry pi, Arduino , Opencv and much more.

You may also like...

15 Responses

  1. Didik Sazali says:

    How to make 2 pictures as splash screen?

    • guru says:

      Hello didik
      Just create 2 splash activities and then show first splash screen. Finish it and then show one and after that show normal app screen.
      Hope you understood. please comment for any other queries

    • AndroidSRC . says:

      Hello didik
      Just create 2 splash activities and then show first splash screen. Finish it and then show one and after that show normal app screen.
      Hope you understood. please comment for any other queries

  2. Lore says:

    Hi, my splash screen is not full screen. How i do to make a full screen? Thank you

  3. Joe says:

    Hi, I followed your steps and the a screen works. however, on my device, i see my app twice. One of them shows the splash screen and the other doesn’t. Thanks in advance

  4. Joe says:

    Hi, I have solved my problem because I have duplicated activities. However, whenever I open the app, it shows the splash screen then says:”Unfortunately [your app] has stopped.” Please help. Thanks again

  5. Yugandhar Vadlamudi says:

    use full for the beginners

  6. Meshack Ogeto says:

    thank you

  1. January 20, 2017

    […] app starts upon clicking of app icon. Splash screen is generally 2-4 sec long. We had earlier added tutorial in which a logo is shown in splash […]

  2. March 28, 2018

    […] Android Splash Screen Tutorial […]

Leave a Reply

Your email address will not be published. Required fields are marked *