How to create Splash Screen in Android

How to create Splash Screen in Android

 Deepanshu Rajora

View (2363)

Android splash screen are normally used to show user some kind of progress before the app loads completely. Splash screen is an activity that will show for set time when your app is starting and after set time period redirect to application main screen.
Some people use splash screen just to show case their app / company logo for a couple of second. In this article, we are going to learn how to implement splash screen in your android application.

Create New Android Project

1. Create a new project and fill the required details File ⇒ New ⇒ Android Project

2. Open splashscreen.xml (res/layout) make screen to behave like your splash screen by placing company logo and background color.  

 

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:background="#2185c5" android:orientation="vertical"
    android:gravity="center">

    <ImageView android:src="@drawable/logo" android:id="@+id/imageView1"
        android:layout_width="match_parent" android:layout_height="wrap_content">
        </ImageView>

    <TextView android:id="@+id/textView1" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:layout_gravity="center">
        </TextView>

</LinearLayout>

     

3. Now open SplashScreen.java Activity class, create object of Handler class and callpostDelayed() method to show splash screen for 5 seconds. After wait of 5 seconds, we will redirect user to HomeScreen and will finish current splash screen.

 

package com.splashscreen.geeksdemy;
 
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
 
public class SplashScreen extends Activity {
 
    // Constant Value for Splash Screen time visibility
    private static int SPLASH_SCREEN_TIME = 5000;
 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splashscreen);
 
        // Create object of Handler class and call method postDelayed to make
        // Splash Screen visible for SPLASH_SCREEN_TIME
        new Handler().postDelayed(new Runnable() {
 
            public void run() {
                // This is method will be executed when SPLASH_SCREEN_TIME is
                // over, Now you can call your Home Screen
                Intent iHomeScreen = new Intent(getApplicationContext(),
                        HomeScreen.class);
                startActivity(iHomeScreen);
 
                // Finish Current Splash Screen, as it should be visible only
                // once when application start
                finish();
            }
 
        }, SPLASH_SCREEN_TIME);
    }
}

       

4. Make sure you have created HomeScreen.java Activity class and respective xml file for GUI.

5. Now execute Application.

 

Points to Remember

  • In Android, No Built in mechanism available for Splash screen
  • Use Handler or Thread class to make Splash Screen visible for few seconds.
  • postDelayed() used to called runnable after specified amount of time
  • Don’t forget to finish()  splash screen, once you redirect to Home Screen.


 If you like this Article and find this helpful, don't forget to like and share with your friends!

 

About the author

Most Read

The new kid in the block: Android Noughat

Google has been following a similar pattern with its Android naming process....

Watch Security Cams in the open using Google dorks

Are you aware that there is no such thing on the internet as, “Hiding in...

How to create Splash Screen in Android

Android splash screen are normally used to show user some kind of progress...

Reasons that prove BIG DATA is the next Big thing!

According to analysts, the big data market has been predicted to be USD $50...

Top 10 reasons why you should learn Java

If you're a programmer now, or you want to become one, you've probably...
X
Register Here
 
By signing up , you agree to our Terms of Service and Privacy Policy.
 Login With
Facebook
Facebook
Google
Google
X
Log In Here
 
Remember me Forgot password?
 Login With
Facebook
Facebook
Google
Google
X
Reset Password
 
X

Confirmation Message

Yes No
X
Forgot Password
 
Do you want to Login ?