DEV Community

Discussion on: Android: Simple way to implement a SplashScreen in your app

Collapse
 
rcosteira79 profile image
Ricardo Costeira • Edited

I prefer doing it without an Activity: create a style for the splash screen and set it as the main activity's style. Then, on the activity's onCreate, set the theme to the default theme and you're done. This immediately displays the splash screen (without that white screen that is sometimes displayed) and eliminates the need for an extra activity just to show the splash screen. However, it has the disadvantage of showing the splash screen again if you navigate to another activity and the main activity gets destroyed (for instance, due to resource constraints).
Regardless, since I've been using a single activity - multiple fragments architecture, the disadvantage doesn't really bother me :)

Collapse
 
artesanoandroid profile image
Alonso Ato Neyra

Looks good because of your architecture but what if you wanna do an animation with the image? or something like that?

Collapse
 
rcosteira79 profile image
Ricardo Costeira

You can add references to animations in a theme. You could, for example, create an animation-list with the animation you want and set it as the theme's windowBackground.

Collapse
 
playboy2123 profile image
kün

can you show me the way in steps plz?

Collapse
 
rcosteira79 profile image
Ricardo Costeira

I have an example of this in a repo:

1 - Create the splash screen style like in github.com/rcosteira79/AndroidMult...

2 - Set it as the main activity's theme like in github.com/rcosteira79/AndroidMult...

3 - Reset the theme in the main activity like in github.com/rcosteira79/AndroidMult...

Thread Thread
 
pshdevio profile image
pshdevio

Thanks Ricardo, this works perfectly !