Implementing Splash Screen In Android Application Tutorial/Example

Android splash screen is usually used to show progress or some kind of loading to show a user that application is  loading data while we can also use the splash screen to show our application logo or display  tagline. Although Android discourages use of splash as users have to wait till to use application. Google’s app don’t have a splash screen. Try to use splash screen when u need to make calls asynchronous calls in the background to load application data.

Basically, we use splash screen in two ways

1.One is to show app/company logo along with tagline.

2.Second when application prepares data in the background to show to the user.

So Lets start

  1. Open Eclipse or Android Studio -> New Project->Android Application Project-> Name of Application-> Follow all instructions and complete by clicking on Finish.

2. For splash screen, we will make separate activity as SplashScreen.java

3. Add to AndroidManifest.xml like this

<activity android:name="com.coderzpassion.splashscreensample.SplashScreen"></activity>

So AndroidManifest.xml will look like this

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.coderzpassion.splashscreensample" >

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.coderzpassion.splashscreensample.SplashScreen"
            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.coderzpassion.splashscreensample.MainActivity"
/>    </application>

</manifest>

 

4. Create layout for SplashScreen.java under layout folder as splashscreen.xml i have created ImageView to show app/company logo and TextView to show tagline.

splashscreen.xml

<?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"
    >
<ImageView
    android:id="@+id/logo"
    android:layout_gravity="center"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/logo"/>

    <TextView
        android:id="@+id/tagline"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Where Android Coding is Passion"
        android:textColor="@android:color/black"/>

</LinearLayout>

 

5. Now Coding SplashScreen.java as

SplashScreen.java

package com.coderzpassion.splashscreensample;

import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.v7.app.AppCompatActivity;


public class SplashScreen extends AppCompatActivity {

    private final int splash_screen_time=3000; //in milliseconds
    Thread splashTread;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splashscreen);
        splashTread = new Thread() {
            @Override
            public void run() {
                try {
                    synchronized (this) {
                        wait(splash_screen_time);
                    }

                } catch (InterruptedException e) {
                } finally {

                    Intent i = new Intent(SplashScreen.this,MainActivity.class);

                    startActivity(i);
                    finish();

                }
            }
        };

        splashTread.start();
    }

}

6. Run this and you will see the splash screen for 3 seconds.

OutPut

Screenshot_2016-02-27-18-10-15