Android: Follow the best practice for create a Splash Screen


Davide Agostini /

2 min read

Hi and welcome in this new tutorial where you will learn the best practice on how to create a splash screen in an Android application.

More developers, usually, for this task, create an activity called SplashScreen and the relative layout where insert a delay of 2-3 seconds before to navigate to the MainActivity. In these seconds it’s show the logo of the app.

This isn't a best practice, insert a delay before to move to another activity is insane.

The users doesn't like to wait!

A simple solution is create a simple drawable resource that I called launch_background.xml where you insert the logo and a background.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/splash_black"/>
    <item android:drawable="@drawable/ic_logo" android:gravity="center" />
</layer-list

Then in my themes.xml file create a theme valid only for the splash screen

    <style name="LaunchTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <item name="android:windowBackground">@drawable/launch_background</item>
        <item name="android:statusBarColor">@color/splash_black</item>
    </style>

After that set this theme as the theme of the main application in AndroidManifest.xml.

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/LaunchTheme"> /* my launch theme */
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

Then in onCreate() of the MainActivity.kt before call setContentView() it's necessary set theme to the main theme. setTheme(R.style.Theme_AndroidSplashScreen)

Run the emulator and see the final result.

android splash screen

No matter if the splash screen is seen for a few moments, remember the user doesn't like to wait!

Link to my source code https://github.com/davideagostini/android_splash_screen

I hope that this tip will help you for your next mobile development.

Before concluding I recommend you to like this post and subscribe to my newsletter to stay updated on new posts.

See you in the next tutorial.  😉

← Back to the blog