Android Splash Screen Example

In this tutorial we will learn about the Splash screen in android. Most of the applications have a Splash screen which opens when the app launches.

Splash in Android
Splash in Android

What Is Splash Screen In Android?

Splash Screen in android is a screen which launches first when we open the application. Generally it show the logo and the name of the application. It is a activity in android studio which is declared in Manifiest.java file inside the intent -filter.

The purpose of Splash Screen is to quickly display a beautiful screen while application fetches the relevant content from local database or the server.

Creating Splash Screen In Android Studio

It is simple activity in android studio. Design the layout part as you want like background logo and the name of the application. We will create in the following way.

activity_splash.xml

In the below layout file I used only the log image in center.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/color_white"
    tools:context=".Activity.Splash">


    <ImageView
        android:id="@+id/imageView"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:background="@drawable/logo"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true" />
</RelativeLayout>

Using Timer Class In Android Splash Screen

To call any method or the class after a given time we can use the Timer() class. The method inside the Timer() class will call after completing the time. In the below Timer() class we will call the MainActivity() class after 3 seconds.

 Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                startActivity(new Intent(this, MainActivity.class));

                finish();
            }
        }, 3000);

SplashActivity.java

We will redirect the SplashActivity() to the the MainActivity() after some seconds. For this we will use the Timer class to class the MainActivity() after some seconds. Use the above Timer() class method to call the MainActivity().

package com.example.cashbeen.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.example.cashbeen.Custom.CustomActivity;
import com.example.cashbeen.R;

import java.util.Timer;
import java.util.TimerTask;

public class Splash extends CustomActivity {

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

        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {

                startActivity(new Intent(this, MainActivity.class));

                finish();
            }
        }, 3000);
    }

}

MainActivity.java

We are not posting the MainActivity.java class code. You should use your class which you want to call instead of MainActivity.java.

Conclusion

There are several ways to create a splash screen in android. We used the Timer() class to do that.

Thank you for visiting this code hope you get your answer. Please do comment for your doubts or any problem.

Don’t miss new tips!

We don’t spam! Read our [link]privacy policy[/link] for more info.

Leave a Comment