What is Splash Screen in Android

What is splash screen in android

Splash in Android Studio is commonly the start of the app and the first screen with which the user interacts. It has logos of app, animations of app contentĀ  In other words, It generally starts for some time at the start of the app i.e,., 4 to 5 seconds or maybe shorter.

Splash Screen has more than one method to start but here we will discuss the smartest way

In Splash Screen we used Image to view in .xml to set the splash screen and pick an image from the drawable folder, and then call in the code

Now in Java, we will set the time to handler and call postdelayed,it will call run method after fixed time

and set to the main screen.

Then,set the time for screen to be displayed 1s = 1000ms

Post Delayed method will delayed the time for time you have set and then displays the main screen

We use the intent function in Android

In Android, we create an activity named splash, In drawable you placeĀ  an image you want to set as splash

Splash.xml

<?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:orientation="vertical">

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/splash"/>

</LinearLayout>

Splash.java

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

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

public class Splash extends AppCompatActivity {
    Handler handler;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

    handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            Intent intent = new Intent(Splash.this,DrawerActivity.class);
            startActivity(intent);
            finish();
        }
    },3000);

    }
}

Leave a Comment