Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why there is a white screen appears for 1sec when starting to run the apps in Android?

Tags:

android

When I click the app icons and start to run the apps, it will appear a white screen for 1 sec.
I don't know why.
Is there any idea to clear this white screen and directly go to my activity?

like image 311
jjLin Avatar asked Dec 01 '22 21:12

jjLin


2 Answers

The white/black screen is the window background image.

The window background is shown while e.g. your onCreate() runs and your layouts are being inflated. It can take some time especially if there's a lot of bitmaps that need to be read, decoded and scaled.

Changing the theme works because some themes have a non-default window background. For example, Theme.Wallpaper has a transparent background. There are other definitions there, too. Essentially what you want is:

<style name="YourTheme">
  <item name="android:windowBackground">@null</item>
</style>

Programmatically you can achieve the same with

getWindow().setBackgroundDrawable(null);

at the top of activity onCreate().

(Old question but got bumped up by another answer and there wasn't a good answer.)

like image 54
laalto Avatar answered Dec 10 '22 12:12

laalto


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

and add below line in your style.xml

    <item name="android:windowDisablePreview">true</item>
 <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>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowDisablePreview">true</item>
</style>
apply changes in AndroidMainfest.xml
 <application
        android:theme="@style/AppTheme">
like image 37
Patel vaishu Avatar answered Dec 10 '22 13:12

Patel vaishu