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.
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Contents
Splash Screen Tutorial for Android
30 mins
- Getting Started
- Choosing the Target SDK Version
- Setting Up the Emulators
- Testing the Default Behavior
- Pre-Android 12 Splash Behavior
- Default Android 12 Splash Behavior
- Splash Screens
- App Startup States
- Splash Screens Over the Years
- Creating a Simple Splash Screen
- Adding the Dependency
- Customizable Elements
- Adding the Adaptive Icon
- Changing the Background
- Setting the Style
- Installing the Splash Screen
- Adding More Customization
- Adding an Icon Background
- Creating a New Style for Android 12
- Adding an Animated Icon
- Adding a Branding Image
- Extending the Duration
- Changing the Exit Animation
- Migrating Your Project
- Legacy Method: Overriding android:windowBackground
- Migrating Away From Overriding android:windowBackground
- Legacy Method: Dedicated Splash Activity
- Adapting the Dedicated Splash Activity
- Where to Go From Here?
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.
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:
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.
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.
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.