Android Splash Screens
Splash screens are good for branding your apps, but forcing it on your users every time they open your app is not a good idea.
Many developers practice the idea of showing the splash screen for a definite period of time (say 3 seconds) every time the app is launched! And they end up writing something like below
Trust me, the idea behind splash screen is definitely not this! This is just forcing your users to stare at your branding logo for 3 seconds and that too for no reason. Your app might be ready to interact even before this time, so you are just wasting your users time to start interacting with your app!
However, Android apps do take some time on startup, especially on cold startup. There is a delay that you will not be able to avoid. Leaving a blank screen is also not a good idea. Why not show the users something nice for exactly the amount of time the app needs to configure itself? Something like below,
Implementing such splash screens a little different, because the view should be ready even before you inflate a layout file in your splash activity. So we will not use a layout file, instead we will use our splash screen’s background as the activity’s theme. Let’s jump to the code,
The above file shows the Manifest file, which has our SplashActivity as our launcher activity, along with a theme “SplashTheme”. Let’s look at SplashActivity code,
As we said, we will not create a layout file for our SplashActivity. Instead we used a theme, let’s look at our SplashTheme,
Our SplashTheme has it’s background as background_splash, here is where all the magic happens! Let’s look at our background_splash inside drawable folder,
This is where we can set our background colour for our splash screen and our branding logo. This is how simple it is!
This is how the outcome looks. The view for your splash screen comes from the theme and it is available immediately.
What if we have used a layout file? The layout file would have only been visible after the app has been configured, which is too late! The splash screen has to be displayed only in that small amount of time when the app is being initialised!
That’s it, no more blank screens, no more delayed splash screens! Happy coding :)