As we all know, many Android apps display a white screen very briefly before their first Activity
comes into focus. This problem is observed in the following cases:
Android apps that extend the global
Application
class and perform major initializations therein. TheApplication
object is always created before the firstActivity
(a fact that can be observed in the debugger), so this makes sense. This is the cause of the delay in my case.Android apps that display the default preview window before the splash screen.
Setting android:windowDisablePreview = "true"
obviously does not work here. Nor can I set the parent theme of the splash screen to Theme.Holo.NoActionBar
as described here, because [unfortunately] my splash screen makes use of an ActionBar
.
Meanwhile, apps that do not extend the Application
class do not show the white screen at startup.
The thing is, ideally the initializations performed in the Application
object need to occur before the first Activity
is shown. So my question is, how can I perform these initializations on app startup without using an Application
object? Possibly using a Thread
or Service
, I suppose?
This is an interesting problem to think about. I can't bypass it the usual way (by setting the NoActionBar
theme), as tragically my Splash screen actually has an ActionBar
due to some unrelated reasons.
Note:
I have already referred to the following questions:
References:
Please copy and paste these two lines in your manifest app theme i.e res/styles/AppTheme. then it will work like charm..
I had same issue, you have to update your style.
style.xml
Your manifest file should looks like below.
Outout:
Hope this would help you.
I would recommend taking a look at the answer given at this page. Solved using the Style property. It does not bother the user.
Have you tried setting the
android:windowBackground
attribute in the theme of your launcher activity, to either a color or a drawable?For example this:
when added to the Launcher activity theme will show a black color (rather than the white color) on startup. This is an easy trick to hide long initialisation, while showing your users something, and it works fine even if you subclass the Application object.
Avoid using other constructs (even Threads) for doing long initialisation tasks, because you may end up not being able to control the lifecycle of such constructs. The Application object is the correct place for doing exactly this type of actions.
Did you try to put initialization to
onActivityCreated
?Inside
Application
class :Recommended way of solving this problem is missing in the answers. So I am adding my answer here. The white-screen-at-startup problem occurs because of the initial blank screen that the system process draws when launching the app. A common way to solve this is by turning off this initial screen by adding this to your
styles.xml
file.But according to android documentation this can result in longer startup time. Recommended way of avoiding this initial white screen according to google is to use activity's
windowBackground
theme attribute and provide a simple custom drawable for the starting activity.Like this:
Drawable Layout file,
my_drawable.xml
Create a new style in your
styles.xml
Add this theme to your starting activity in the Manifest file
And when you want to transition back to your normal theme call
setTheme(R.style.Apptheme)
before callingsuper.onCreate()
andsetContentView()
This is the recommended way to solve the problem and this is from google Material Design patterns.