How To fix white screen on app Start up?
Asked Answered
M

18

123

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.

Morena answered 12/12, 2013 at 14:52 Comment(5)
The activity that you are starting is taking too long to do its onCreate part. Try to just "setContentView" in that activity and check if this delay is gone.Stilbite
sorry i am a newbie and i have no experience with java, can you please explain clearly? and please give an "answer" so that i can tick it :)Morena
Are you using java or c# in your project?Stilbite
Hope this link will help you: cyrilmottier.com/2013/01/23/android-app-launching-made-gorgeousGeisel
@VivekKumarSamele - the domain geeksforandroidgeeks.com expired May 4, 2020Runyon
C
112

Just mention the transparent theme to the starting activity in the AndroidManifest.xml file.

Like:

<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>

and extend that screen with Activity class in place of AppCompatActivity.

like :

public class SplashScreenActivity extends Activity{

  ----YOUR CODE GOES HERE----
}
Creeper answered 13/12, 2013 at 6:9 Comment(8)
but using final ActionBar actionBar = getActionBar(); will return null when the Theme is translucentOuting
Pankaj - yes, I learned that the bad UI experience was due to the "preview" window... apparently someone at Google decided that a white preview window was really awesome to use by default. However, in an app that uses a dark background it's a really bad idea. The solution is to create a custom style for your app and specify 'android:windowBackground' to the color you want to use. See the section "the perfect preview window" cyrilmottier.com/2013/01/23/android-app-launching-made-gorgeousOuting
Thanks buddy i was in a hunt for Theme.Translucent.NoTitleBar :)Carleton
@Hagai L It's give me an error like as "java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity."Screeching
android:theme="@android:style/Theme.Translucent.NoTitleBar" did not work for me, any suggestions?Festschrift
I set the android:theme on application tag. Is that different from setting it on Activity tag in the manifest?Razee
@Screeching to get stop error "java.lang.IllegalStateException" you have to extends your Activity by android.app.Activity, right now you are using AppCompactActivity. So for AppCompactActivity you cannot use normal themes.Fredericafrederich
When I try with Theme.Translucent.NoTitleBar then app is taking time in lauching. It seems like first launch activity is drawing the translucent theme to overcome the white screen issue and then its draw the content view. Any idea about this? How to overcome this delay issue, I checked with Play Store app also that is also taking time to launch but very less approx 300ms but mine is taking 700ms to 1s.Fredericafrederich
R
170

Put this in a custom style and it solves all the problems. Using the hacky translucent fix will make your task bar and nav bar translucent and make the splashscreen or main screen look like spaghetti.

<item name="android:windowDisablePreview">true</item>

Repertory answered 23/1, 2016 at 6:15 Comment(3)
Although this works like a charm, there is a bit of a lag in loading the app when a user clicks on the icon to launch the app. Other than this, no particular tradeoff.Peace
I think this makes a delay in app startingDamalis
This is not a good solution, actually is not a solution at all, just makes the white screen Transparent but still takes some seconds to load the Launcher screen, feels like a buggy appTuroff
C
112

Just mention the transparent theme to the starting activity in the AndroidManifest.xml file.

Like:

<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>

and extend that screen with Activity class in place of AppCompatActivity.

like :

public class SplashScreenActivity extends Activity{

  ----YOUR CODE GOES HERE----
}
Creeper answered 13/12, 2013 at 6:9 Comment(8)
but using final ActionBar actionBar = getActionBar(); will return null when the Theme is translucentOuting
Pankaj - yes, I learned that the bad UI experience was due to the "preview" window... apparently someone at Google decided that a white preview window was really awesome to use by default. However, in an app that uses a dark background it's a really bad idea. The solution is to create a custom style for your app and specify 'android:windowBackground' to the color you want to use. See the section "the perfect preview window" cyrilmottier.com/2013/01/23/android-app-launching-made-gorgeousOuting
Thanks buddy i was in a hunt for Theme.Translucent.NoTitleBar :)Carleton
@Hagai L It's give me an error like as "java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity."Screeching
android:theme="@android:style/Theme.Translucent.NoTitleBar" did not work for me, any suggestions?Festschrift
I set the android:theme on application tag. Is that different from setting it on Activity tag in the manifest?Razee
@Screeching to get stop error "java.lang.IllegalStateException" you have to extends your Activity by android.app.Activity, right now you are using AppCompactActivity. So for AppCompactActivity you cannot use normal themes.Fredericafrederich
When I try with Theme.Translucent.NoTitleBar then app is taking time in lauching. It seems like first launch activity is drawing the translucent theme to overcome the white screen issue and then its draw the content view. Any idea about this? How to overcome this delay issue, I checked with Play Store app also that is also taking time to launch but very less approx 300ms but mine is taking 700ms to 1s.Fredericafrederich
R
73

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">
Riggle answered 14/10, 2015 at 11:21 Comment(0)
J
8

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.

Javelin answered 12/12, 2013 at 14:57 Comment(0)
U
6

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.

Unswear answered 6/7, 2016 at 17:9 Comment(0)
E
4

Both properties works use any one of them.

    <style name="AppBaseThemeDark" parent="@style/Theme.AppCompat">
            <!--your other properties -->
            <!--<item name="android:windowDisablePreview">true</item>-->
            <item name="android:windowBackground">@null</item>
            <!--your other properties -->
    </style>
Engelhart answered 18/8, 2016 at 9:9 Comment(0)
B
4

The white background is coming from the Apptheme.You can show something useful like your application logo instead of white screen.it can be done using custom theme.in your app Theme just add

android:windowBackground=""

attribute. The attribute value may be a image or layered list or any color.

Broncho answered 1/11, 2016 at 10:8 Comment(3)
This works, Better if you set transparent color to window. <item name="android:windowBackground">@android:color/transparent</item>Equivalency
This should be the accepted answer . Anyways do you know how to add the animation of scaling like youtube app.Mamie
Instead of White now it's black.Clung
S
3

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!

Stereochemistry answered 21/9, 2016 at 11:34 Comment(1)
i tried this solution many times as everywhere wrote this same solution, it couldn't work -- > but your BUT save my time my Activity extends AppCompatActivity that's why it's not working i changed it to activity now it works thank you man!!Ablaut
S
2

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>
Sheol answered 6/2, 2018 at 10:48 Comment(0)
W
2

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.

Wirra answered 24/6, 2018 at 8:31 Comment(2)
Please add the details directly to your answer. Links can become invalid, that's why we like for the answer to contain the actual content, the link being only supplementary.Formulary
The link is to her own blog post, and it's the same info. >.> Also, as others have said elsewhere here making it translucent leaves it inaccessible later.Churchgoer
G
1

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!

Gormley answered 30/6, 2016 at 12:16 Comment(0)
W
1

you should disable Instant Run android studio Settings.

File>Settings>Build,Execution, Deployment>Instant Run unCheck all options shown there.

Note: White screen Issue due to Instant Run is only for Debug builds,this Issue will not appear on release builds.

Whiteman answered 23/8, 2017 at 10:5 Comment(0)
S
1

Its Solution is very Simple!

There are Three Basic Reasons for This problem

  1. You are doing Heavy / Long running / Complex task in onCreateVeiw Function.
  2. If your are using Thread. Then Thread Sleep time may be very large.
  3. 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.

Snowblink answered 19/6, 2019 at 19:12 Comment(0)
U
1

White background is caused because of the Android starts while the app loads on memory, and it can be avoided if you just add this 2 line of code under SplashTheme.

<item name="android:windowDisablePreview">true</item>
<item name="android:windowIsTranslucent">true</item>
Uchida answered 27/6, 2019 at 1:50 Comment(0)
H
1

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.

Hixson answered 27/4, 2020 at 0:30 Comment(0)
M
1

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>
Minuend answered 1/7, 2020 at 21:59 Comment(0)
D
0

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.

Deutoplasm answered 30/1, 2019 at 5:40 Comment(1)
Code-only answers are discouraged. Please click on edit and add some words summarising how your code addresses the question, or perhaps explain how your answer differs from the previous answer/answers. From ReviewParadiddle
S
0

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

Stichter answered 13/7, 2023 at 3:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.