The right way to implement a Splash Screen in Android

Splash Screen one of the exciting feature in android, is referred to a welcome screen or user’s first experience of an application. A professionally designed Splash Screen has a possibility of making your Application look more professional.

Unfortunately in android we don’t have any inbuilt mechanism to show splash screen compared to iOS. But there are multiple ways to implement Splash Screen for an Android App. In this article, we will walk through 2 common methods of implementing splash screens and will find the right way:

  1. Using Timers (the bad)
  2. Using a Launcher Theme (The Right way)

Method 1: Using a timers

Method 2: Using a Launcher Theme

  • Create background for splash screen splash_screen_background.xml in res/drawable directory.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<item android:drawable="@android:color/holo_purple" /><item>
<bitmap
android:gravity="center"
android:src="@drawable/app_logo" />
</item>
</layer-list>
  • Create Style for Splash Screen in res/values/style.xml.
<style name="SplashScreenTheme", parent = "Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/launcher_screen_with_logo</item>
</style>
  • Set the style as theme for SplashScreenActivity in AndroidManifest.xml
<activity android:name=".SplashScreenActivity"
android:theme="@style/SplashScreenTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>.Time for Splash Screen:

The time for Splash Screen:

We have already a theme to show as splash screen. Now need the time for showing it. Okay In method 1, if you notice carefully you will find a white blank screen before opening your splash screen. Do you know why it happens ? This happens because of ‘Cold Start’. ‘Cold Start’ is the time taken from the moment the code is initialized till the UI is responsive to the user. It happens in cases such as your app is being launched for the first time since the device booted, or since the system killed the app.

So, In this method we will use this cold start time to show our splash screen. Here we have no exact time for splash screen rather it will take the cold start time. And when onCreate() will be called, we will redirect to MainActivity() and finish the SplashSreenActivity.

*As we are loading the splash screen them from manifest. So there is no need to setContentView() with any xml layout.

public class SplashScreenActivity extends AppCompatActivity {@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
startActivity(new Intent(SplashScreenActivity.this, MainActivity.class));
finish();
}
}

Happy Coding:)

Written by

{ 'designation' : 'Software Engineer' , 'hobby' : [ 'Music', 'Photography', 'Travelling' ] ,’email’: ‘shishirthedev@gmail.com’ }

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store