Splash Screen Tutorial for Android

Learn how to implement splash screen in new and existing Android apps, using the SplashScreen API introduced in Android 12. By Jemma Slater.

5 (9) · 4 Reviews

Download materials
Save for later
Share
You are currently viewing page 4 of 4 of this article. Click here to view the first page.

Migrating Away From Overriding android:windowBackground

The steps to update this method are straightforward — by this point in the tutorial, you have already learnt everything you need to know! Recreate your original splash screen in a new theme using the steps described earlier in the tutorial. The SplashScreen API is a little more restrictive in its design, but you can still make major improvements in your app experience by customizing away from the default screen.

In AndroidManifest.xml, set the MainActivity theme back to the new splash style you created earlier:

android:theme="@style/Theme.App.Starting"

Navigate to MainActivity.kt. In onCreate(), uncomment the functions:

val splashScreen = installSplashScreen()
...
setupSplashScreen(splashScreen)

This adds back the plumbing for the SplashScreen API as implemented earlier. Finally, in onCreate(), remove:

// TODO: (Legacy Migration) Remove old app theme
setTheme(R.style.AppTheme)

With the SplashScreen API, the activity no longer needs to manually reset the theme after the splash screen dismisses. This is handled by the postSplashScreenTheme attribute in the new style.

And that’s all there is to it. Now your app displays the customized splash screen on all versions of Android!

Legacy Method: Dedicated Splash Activity

The other common way to add a custom splash screen was to use a dedicated activity. This was often used when the app needed to execute some logic before allowing entry to the app, such as loading settings or processing navigation logic.

If you previously implemented this method, your app probably now has two splash screens on Android 12, as the default splash screen shows before your custom activity. This can look jarring, and it isn’t a good user experience.

Try to migrate from using a separate activity. But, if your app requires it, you can prevent the activity from being shown and hold the user on the default splash until the app is ready.

Before you start, update the starter project. Open AndroidManifest.xml. Find the TODO in the LegacySplashActivity block, and uncomment:

<intent-filter>
 <action android:name="android.intent.action.MAIN" />
 <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

Find the same intent-filter block in the MainActivity and remove it. These changes mean the LegacySplashActivity is now the launching activity.

On both emulators, build, run and relaunch the app. You’ll see Android 10 shows the legacy splash screen until the app is ready. Android 12, however, shows the new default splash screen before the legacy screen, resulting in two splash screens.

Video demo of the duplicated splash screen

Adapting the Dedicated Splash Activity

You can keep your dedicated activity and avoid having two splash screens by implementing the SplashScreen API. In LegacySplashActivity.kt, add the following to the top of onCreate():

val splashScreen = installSplashScreen()

Then replace the remaining TODO:

splashScreen.setKeepOnScreenCondition { true }

This installs the splash screen, then uses setKeepOnScreenCondition to prevent it from dismissing. The launching activity never renders on the screen, and the splash displays until the next activity is ready, providing a smooth transition into the app.

Your LegacySplashActivity.kt should look like this:

Screenshot of the LegacySplashActivity.kt file

Build and run on API 31 and relaunch. This time, only the default splash is shown. It overrides the legacy theme because the LegacySplashTheme doesn’t have the SplashScreen API parent. Updating your customized splash theme to use the SplashScreen API parent will allow it to show.

Note: If your app uses a dedicated splash screen activity, adding the support for SplashScreen API will also improve your app launch experience. Precisely, it does so by rendering the splash screen even before executing onCreate() of the Application class, which on the contrary, in case of dedicated splash screen activity, gets rendered after the execution of Application’s onCreate(), during the Activity’s onCreate().

Where to Go From Here?

Download the final project by clicking Download Materials at the top or bottom of this tutorial.

Android with confetti

You’ve learned splash screen is a critical aspect of the user experience on modern devices and how to use the SplashScreen API to provide a smooth experience for users. Test your existing projects to ensure they’re compatible with Android 12. You can follow the migration steps above to add support in older projects.

Once your splash screen works across all Android versions, experiment further with extra customizations. Try various exit animations or adding sparkle to your icon.

Interested in more Android 12 updates? Check out the RenderEffect API.

If you have any comments or questions, join the forum discussion below.