Image for post
Image for post

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!

Senior Software Engineer at OLX

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store