Android Splash Screen Example

In this tutorial you will get android splash screen example.

Splash screen is a simple screen or activity used to display some progress when application is launched. Some developers use splash screen to just show company logo or to engage user while some important data in loaded in background. After few seconds or minutes splash screen is stopped and any other activity is started.

Below I have given an example of splash screen of Facebook app. This screen appears for few seconds when app is launched.

facebook splash screen

Android Splash Screen Example

Create new project with a blank activity with name Splash. Use package name as com.splash. Now create another blank activity with name MainActivity, it is the activity that will open after splash screen.

Note: Make sure Splash is launcher activity.

Copy any image with name logo in res/drawable folder. We will use this logo to show on splash screen.

Now add following codes in respective files.

Splash.java

package com.splash;

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

public class Splash extends Activity {

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

        //creating thread that will sleep for 10 seconds
        Thread t=new Thread() {
            public void run() {

                try {
                        //sleep thread for 10 seconds, time in milliseconds
                        sleep(10000);

                        //start new activity
                        Intent i=new Intent(Splash.this,MainActivity.class);
                        startActivity(i);

                        //destroying Splash activity
                        finish();

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

        //start thread
        t.start();
    }
}

 

activity_splash.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:paddingTop="16dp"
    android:paddingBottom="16dp" tools:context="com.splash.Splash">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/logo"
        android:layout_gravity="center"/>
</LinearLayout>

 

MainActivity.java

package com.splash;

import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

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

 

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:paddingTop="16dp"
    android:paddingBottom="16dp" tools:context=".MainActivity">

    <TextView android:text="Hello World" android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>

 

Android Splash Screen Example
I have used Thread class and sleep() method to keep splash screen for 10 seconds. You can change the time according to you. After that Intent class is used to open MainActivity.

If you are facing any problem related to above android splash screen example then feel free to ask it by commenting below.

Happy Coding!! 🙂 🙂

3 thoughts on “Android Splash Screen Example”

  1. Hello i want to Copy Sofware From Feature Phone to Pc or Android so what to doo.. its Keypad Basic Colure Phone…
    Please inform me thank you…

  2. hi
    can you give tutorial on how to fetch the files in android..? files in the sense if i want to scan files or particular folder for just checking desired file is in there at that folder or not by coding in android studio…if you can…please help me for this..?

Leave a Comment

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