I have an android app which displays a white screen for 2 seconds on startup. My other apps don't do this, but this one does. I have also implemented a splashscreen with the hope that it would fix this. Should I increase my splash screen sleep time? Thanks.
How To fix white screen on app Start up?
126.7k views Asked by Anonymous AtThere are 18 answers
You should read this great post by Cyril Mottier: Android App launching made gorgeous
You need to customise your Theme
in style.xml and avoid to customise in your onCreate
as ActionBar.setIcon/setTitle/etc.
See also the Documentation on Performance Tips by Google.
Use Trace View
and Hierarchy Viewer
to see the time to display your Views: Android Performance Optimization / Performance Tuning On Android
Use AsyncTask
to display some views.
Setting "android:windowBackground" with the image, removes the white/black screen and shows the image instead
<item name="android:windowBackground">@drawable/launch_screen</item>
where "launch_screen" is an image of format png placed inside drawable folder
Note: You do not need to specify the format while using image
i also had the same problem in one of my project. I resolved it by adding some following parameters in the theme provided to the splash screen.
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowIsTranslucent">true</item>
You can find the reason and resolution in this blog post written by me. Hope it helps.
This solved the problem :
Edit your styles.xml file :
Paste the code below :
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowIsTranslucent">true</item>
</style>
</resources>
And don't forget to make the modifications in the AndroidManifest.xml file. (theme's name)
Be careful about the declaration order of the activities in this file.
Try the following code:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowIsTranslucent">true</item>
</style>
This code works for me and will work on all Android devices.
Make a style in you style.xml as follows :
<style name="Theme.Transparent" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowIsTranslucent">true</item>
</style>
and use it with your activity in AndroidManifest as:
<activity android:name=".ActivitySplash" android:theme="@style/Theme.Transparent">
It can be fixed by setting the theme in your manifest as
<activity
android:name=".MySplashActivityName"
android:theme="@android:style/Theme.Translucent.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and after that if you are getting
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
then you may need to extend Activity instead of AppCompatActivity in your MySplashActivity.
Hope it helps!
This is my AppTheme on an example app:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowIsTranslucent">true</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
As you can see, I have the default colors and then I added the android:windowIsTranslucent
and set it to true
.
As far as I know as an Android Developer, this is the only thing you need to set in order to hide the white screen on the start of the application.
The user543 answer is perfect
<activity
android:name="first Activity Name"
android:theme="@android:style/Theme.Translucent.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
But:
You'r LAUNCHER Activity must extands Activity, not AppCompatActivity as it came by default!
I encountered a similar problem and to overcome it, I implemented the below code in styles, i.e res->values->styles->resource tag
<item name="android:windowDisablePreview">true</item>
Here is the whole code:
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowDisablePreview">true</item>
</style>
Its Solution is very Simple!
There are Three Basic Reasons for This problem
- You are doing Heavy / Long running / Complex task in onCreateVeiw Function.
- If your are using Thread. Then Thread Sleep time may be very large.
- If You are using any Third Party library. Which is initialize at app start up time it may leads this problem.
Solutions:
Solution 1:
Remove the Heavy Task from onCreateView() function and place it some where appropriate place.
Solution 2:
Reduce the Thread Sleep time.
Solution 3:
Remove the Third party library at app initialize at implement them with some good strategy.
In my Case i am using Sugar ORM which leads this problem.
Share to improve.
Below is the link that suggests how to design Splash screen. To avoid white/black background we need to define a theme with splash background and set that theme to splash in manifest file.
https://android.jlelse.eu/right-way-to-create-splash-screen-on-android-e7f1709ba154
splash_background.xml inside res/drawable folder
<?xml version=”1.0" encoding=”utf-8"?>
<layer-list xmlns:android=”http://schemas.android.com/apk/res/android">
<item android:drawable=”@color/colorPrimary” />
<item>
<bitmap
android:gravity=”center”
android:src=”@mipmap/ic_launcher” />
</item>
</layer-list>
Add below styles
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<!-- Splash Screen theme. -->
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/splash_background</item>
</style>
In Manifest set theme as shown below
<activity
android:name=".SplashActivity"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Just mention the transparent theme to the starting activity in the AndroidManifest.xml file.
Like:
and extend that screen with
Activity
class in place ofAppCompatActivity
.like :