Android Splash Screen: Proper way
Splash Screen is the first thing users see when they launch the application and it’s a crucial screen for most of the apps and it allows the app to get things ready for a smooth session.
There are two ways of doing the splash screen and both have its pros and cons.
1. Full-Screen Activity with a Timer (Traditional way) :
This approach allows to create more complex and dynamic splash layout but this takes some time to render and users might see the splash after a small delay. also, users may see white or black ( or windowBackgroundColor ) background just before the splash’s screens layout is displayed.
2. Using a Launcher Theme for the activity ( timer if more time required )
This is the fastest and proper way of using the splash while mitigating the above approach’s cons. But this limits having a dynamic splash( dynamic text, images.. etc) but still, you can create a complex splash using image resources.
Did you know?
When the Android OS calls for an activity, it first looks in the manifest whether any theme is declared for the activity and if so, load that theme before anything.
Let’s get started, shall we?
Step 1
Create a background resource file in drawable folder for splash screen and name it as splash_background.xml
Step 2
Create the gradient_bg.xml. Background can be a gradient, color or image.
Step 3
Create the SplashActivity.kt and set the theme in AndroidManifest.xml
That’s it. Simple as that.
Since we are using a theme to show the splash and style is defined in the manifest, We DO NOT need to use the setContentView() in the activity.