App Turns White Temporaryly when Intent is set with FLAG_ACTIVITY_NEW_TASK and FLAG_ACTIVITY_CLEAR_TASK
Asked Answered
F

2

5
Intent intent = new Intent(LoginActivity.this, Profile.class);

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

startActivity(intent);

overridePendingTransition(R.anim.pull_in_right, R.anim.push_out_left);

I am using this flags to clear all activity stack after logging in. The problem is, the transition became really ugly since the screen turns to white momentarily. Any workaround to avoid this?

P.S.: Both activities has RED Color as their background. I am wondering where the white color cames from.

Fiden answered 2/1, 2016 at 12:26 Comment(2)
This white color shows when activity change take more time. May be any network or something else is taking more time to load activityConvulsion
Yes, but is there any work around we could do? Since this does not happen when I simply start activity without that flags. @CreativeAndroidFiden
C
12

Add below line in your app theme which disable windows preview before fragment or activity load.(white screen problem)

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

See here

Creamcups answered 2/1, 2016 at 12:45 Comment(2)
Unfortunately, if you do that the previous screen will keep "frozen"/unresponsive while the new one load. You should use other techniques to place a loading drawable as background of your window.Opine
Yes we can add background in theme and apply that theme to our activity. Which avoid white screen problem. Will update my answer. Thanks @htafoya.Creamcups
B
2

In your styles.xml file add this line:

<style name="AppTheme" parent="Theme.AppCompat">
    <item name="android:windowDisablePreview">true</item>
...
</style>

It will disable preview mode for the new loaded screen (aka white/black screen).

If you want to use a custom background before loading a new screen, consider adding the following line:

<style name="AppTheme" parent="Theme.AppCompat">
    <item name="android:windowBackground">@drawable/slash_screen</item>
...
</style>
Bookkeeper answered 22/5, 2018 at 8:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.