Correct Way to Add a Splash Screen in Android
Google previously advised against utilizing a Splash Screen for Android Applications. It was pointless. Then, when they released the Material Design Specifications, several of us noticed that the Splash Screen had been renamed Launch Screen. Ideal for displaying your brand. So, what is the distinction between a terrible LaunchScreen and a good LaunchScreen?
So you’re undoubtedly asking, “How difficult can it be to create the ideal splash screen?” And you’re probably correct – we’re talking about a screen that will only be displayed for a few seconds (if that). And a screen that seems to flash a logo at the user before disappearing. So it can’t be that complicated. Nope!
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
Step by Step Implementation
Step #1: Creating a Background XML
To make a proper Splash Screen, you must first build a background that will display your brand’s logo on the screen. You must create an XML file in the res/drawable folder for this.
Step #2: Creating a dedicated custom theme for your Launch Screen
The following step is to design a unique theme for your Splash Activity.
GeekTip: The theme should be inherited from Theme.AppCompat.NoActionBar, because we don’t want that status bar visible when we are showing Launch.
Step #3: Finally some code cooking
Now comes the fun part, where we control the launch screen, in the right way! The best part here is that unlike the conventional methods to add a Splash Screen there is no need to specify a content view for the SplashActivity because the SplashTheme will be applied to it. So, all you have to do is start your Android application’s MainActivity and then end the SplashActivity by using the finish() function. Here is the activity:
Step #4: Finally, setting up the theme
Now we have cooked everything, the only thing left now is to apply the theme for our activity which we created earlier in Step #2, that is pretty easy, just pop the Android.Manifest file and edit it the following way.
And just like that you have the Splash Screen in the right manner, this method is so good that even if your app gets a cold start, even then there is no white theme, because the Android OS fetches the theme from the Manifest first, which makes up the time for the Splash!