Splash Screen in Android: The Right Way
After a research, I’ve found a lot of tutorials about splash (or launch) screen implementations on Android, but developers usually add a Runnable with a fixed time as delay to solve it. That solution was not an option for me, because I don’t want to force my app users to wait when there is nothing to load actually. Let me show you a great solution with minimal modifications that shows the splash screen while the app is loading.
Let’s code
First, we have to design the splash screen layout as a drawable. I’ve used my app logo as the center bitmap, and the primary color as background.
Now, we need to define a theme with the windowBackground value as the previous drawable.
Then, the theme must be assigned to the Main activity.
Finally, we have to replace the splash theme with the original of the Main activity.
Conclusion
With this approach, the splash screen is showed during the app initialization when it’s useful. Also, there is no need to create an extra activity to launch the splash, preventing delays associated with the activity creation. Keep the splash drawable as simple as possible, and you’ll love how fast it works.
That’s all folks!