Android 12 — App Launch Splash Screen

The fact that I can plant a seed and it becomes a flower, share a bit of knowledge and it becomes another’s, smile at someone and receives a smile in return, are to me continual spiritual exercises.
- Leo Buscaglia

Android 12 comes up with new behavior changes that may effect your app. Splash screen is one of them.

Android 12 introduces splash screens for all apps. Apps can customize the splash screen in a number of ways to meet their unique branding needs.

To start with Android 12 splash screen, we first need to understand about Cold Start, Hot Start and Warm Start

Cold Start : A cold start refers to an app’s starting from scratch. It happen when your app’s being launched for the first time since the device booted, or since the system killed the app.

Hot Start: In a hot start, all the system does is bring your activity to the foreground. If all of your application’s activities are still resident in memory, then the app can avoid having to repeat object initialization, layout inflation, and rendering. The system process displays a blank screen until the app has finished rendering the activity.

Warm Start: A warm start is when the app is running and the user decides to restart or reset it. Below are scenarios for warm start:

  • The user backs out of your app, but then re-launches it. The process may have continued to run, but the app must recreate the activity from scratch .
  • The system evicts your app from memory, and then the user re-launches it. The process and the activity need to be restarted.

Starting in Android 12, the system will always apply new default splash screen on cold and warm starts for all apps which will use your app’s launcher icon and the windowBackground of your theme (if it's a single color).

If you are using a custom splash screen in Android 11 or lower, you’ll need to migrate your app to the new splash screen.

If you do not migrate your app, your app launch experience on Android 12 and higher will be either degraded or may have unintended results:

If your existing splash screen is implemented using a custom theme that use windowBackground, then system replaces your custom splash screen with a default Android system splash screen on Android 12 and higher.

If your existing splash screen is implemented using a Activity with the use of handler, then it will result to duplicate splash screens in Android 12 or higher results.

Splash Screen

Splash screen refers to starting screen. It’s provide a smooth transition into the app while it’s loading. When user tap on launch icon then it immediately appears until the app is fully functional.

The splash screen is never shown during a Hot start.

How to implement it ?

You can use the splash screen API directly. But for backward compatibility, we have to use Androidx splash screen compat library for consistent look and feel across all Android versions. If you choose to migrate using the SplashScreen API directly, on Android 11 and lower your splash screen looks exactly the same as it did before; starting on Android 12, the splash screen will have the new Android 12 look and feel.

  1. In module level build.gradle file, set compleSdk as 31 and add splash screen compat library in dependencies section.

2. Now, create a custom theme and use Theme.SplashScreen as it's parent and set the values of attributes to the theme.

If you already have a legacy splash screen implementation that uses attributes like android:windowBackground, consider providing an alternate resource file for Android 12 and higher.

Attributes to set a theme for the splash screen

  1. Use windowSplashScreenBackground to fill the background with single color.
  2. Use windowSplashScreenAnimatedIcon to replace a center icon. If you want to use animated drawable, then use AnimationDrawable or AnimatedVectorDrawable.
  3. Use windowSplashScreenAnimationDuration to set the duration of the splash screen icon animation.
  4. Use postSplashScreenTheme to set the base app theme after splash screen finish. This is required otherwise you will get an exception (IllegalStateException : You need to use a Theme.AppCompat theme (or descendant) with this activity).
  5. Use windowSplashScreenIconBackgroundColor to set a background behind the splash screen icon.
  6. Use windowSplashScreenBrandingImage to show an image at bottom of splash screen. Unfortunately this is only supported for Android 12+. This image needs to have the following properties…
  • It should be within 200dp width and 80dp height.
  • Use SVG or Drawable XML so that it will scale properly in all devices.
  • It should be in a rectangular aspect ratio. Squares and circles are likely to be cut off.

7. Also, please don’t forget to add configurations for status bar and navigation bar to make sure you have a consistent theme applied when launching the app because your base theme isn’t being used yet and leaving them with default values may result in default black bars on the status bar and navigation bar on lower versions.

8. Now, In manifest, replace the base theme to the custom theme you created for splash screen.

9. Now, call installSplashScreen() in the launcher activity before calling setContentView. It enables support for Splash Screen API and proper Android 12+ support. It returns the splash screen object to customize animation or keep the splash screen on for a longer duration or use setKeepVisibleCondition to stay splash visible until the condition isn’t met anymore. The condition is evaluated before each request to draw the application, so it needs to be fast to avoid blocking the UI..

If you are not using installSplashScreen() then you will get an exception (IllegalStateException : You need to use a Theme.AppCompat theme (or descendant) with this activity) in Android 12.

Keep the splash screen on for longer periods

The splash screen is dismissed as soon as your app draws its first frame. If you need to load some data then you can use viewTreeObserver.addOnPreDrawListener to suspend the app to draw its first frame.

Customize Splash Screen Exit Animation

Use splashScreen to customize the animation and splashScreenView.remove to exit the splash screen animation.

Still there are some drawbacks to use splash screen api that I face during development. It’s still in alpha so may be it will overcome in upcoming releases.

a) windowSplashScreenBackground supports only single colour. Waiting for the support of vector drawables.

b) There is no design specifications available for icon and branding images. Still what I find out, that one have to use within 120dp.

c) It doesn’t support icon animation and add a branding image in lower versions.

d) There is some jerk or flickering issue when set exit animation for splash screen.

Demo

Still, Devs get your hands dirty on splash screen api. Let’s learn together.

To get better understanding and coding part, Please go through GitHub link:
GitHub Link : https://github.com/swatiomar27/SplashScreenApiDemo

Happy Coding :)

I hope you liked the article. Feel free to share any feedback. And stay tuned for more concepts!

Don’t forget to follow me on Medium. If you liked the article, click the clap below so more people can see it!

Thanks !!!

As a girl programmer, to keep learning and help ones who needs the skills to be a master, I am available to be a part of an adventurous journey….