Working with Splash Screen API in Android: Part 1
--
The latest and recommended way for consistent app startup experience
Why
This is the question we ask Google or Android team every time whenever they introduce something which we as a developer thinks — Do we really need this new API?
We are really enjoying our old school way of setting up our custom activities which will act as a splash screen or in simple terms launcher screen for our apps by placing some handler or delay functions to hold that screen for some time and then launch then main app screen. But Google has some other ideas or we can say some better, more futuristic idea in their camps for simple yet crucial splash screen feature for our apps.
Introduction
They introduced the new Splash Screen API for more consistent app startup experience across apps for your users. Starting from Android 12, our apps will show the app icons on initial app startup without us doing anything in that app. But yes, we can customize this whole experience by provide our custom values, drawables, and, colors to this new splash screen thing.
Initially we can update the compileSdkVersion to 31 (if not updated already) in our app level build.gradle file and then launch our app in any Android 12 device to see the magic of new Splash Screen thing happening in our app.
But now if you try to run that same app in below Android 12 devices, then that same magic will not happen as expected because Google has different ways to help you out from different situations like they have introduced this new Splash Screen API or library for backward compatibility which you can implement to raise the bar of your app startup experience.
Let’s check out the steps to implement this new API in our apps:
Step 1: Add this library in your app level build.gradle file and hit “Sync now” -
implementation 'androidx.core:core-splashscreen:1.0.0-beta01'
Step 2: Add this code block to your theme.xml file -
<style name="Theme.AppSplashScreen" parent="Theme.SplashScreen">
// Set the splash screen background…