paint-brush
How to Make Splash Screen in Androidby@akshay-rana-gujjar
1,373 reads
1,373 reads

How to Make Splash Screen in Android

by Akshay RanaApril 5th, 2020
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

How to Make Splash Screen in Android: How to add a Splash screen in an App. The Splash screen is an activity with a timer to open the next activity it is as simple as that. The Splash Screen Activity will be called. If we run our app we can see our designed splash screen as per our requirement. The splash screen is a graphical control element consisting of a window containing an image, a logo, and the current version of the software. A splash screen usually appears while a game or program is launching.

Company Mentioned

Mention Thumbnail
featured image - How to Make Splash Screen in Android
Akshay Rana HackerNoon profile picture

Hello World, Today we are going to see how we can make a beautiful Splash Screen in your Android App.

Before start coding let's see, According to Wikipedia what is splash screen:

A splash screen is a graphical control element consisting of a window containing an image, a logo, and the current version of the software. A splash screen usually appears while a game or program is launching. 

A splash page is an introduction page on a website.[1][2] A splash screen may cover the entire screen or web page, or may simply be a rectangle near the center of the screen or page. The splash screens of operating systems and some applications that expect to be run in full screen usually cover the entire screen.

So basically a Splash Screen is when you start an app the first screen with some graphics is a Splash Screen. See below as an example of the Whatsapp splash screen.

How to add a Splash screen in an App

In android, the Splash screen is an activity with a timer to open the next activity it is as simple as that.

So let's create a new activity in our app and we name it as SplashScreenActivity.

Now by default, we have launching activity is MainActivity we need to change launching activity with SplashScreenActivity. To do this go to your manifest.xml file and cut the main activity's intent filter and paste in splash screen activity.

See below.

Now if we run our app and launch it, The Splash Screen Activity will be called.

See also: Pass Data between Activities

Okay, now we will design our splash screen as per our requirement.

I am adding a textview and app logo in the splash screen see below.

Now if we run we can see our designed splash screen.

Now we need to add a timer that will trigger our next activity.

To add a delay or timer we will use Handler Class in android and use its postDelayed method and pass the Runnable interface and implement its run method.

In the run method, we will call our next activity and finish SplashScreenActivity.

See the below code.

public class SplashScreenActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash_screen);
      
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                startActivity(new Intent(SplashScreenActivity.this, MainActivity.class));
                finish();
            }
        }, 2000);
    }
}

After passing the runnable interface we need to pass time in milliseconds, here we are passing 2000 which means 2 seconds.

Now run your app and check your splash screen.

Your Splash screen is ready to rock. Hope you learned something new.

Thank you or reading. Have a nice day.

This article originally published here: https://www.akshayrana.in/2020/03/how-to-make-splash-screen-in-android.html

See Also: Load Image from URL in Android