简体   繁体   中英

White screen is displayed while switching between Activities

When I move from one Activity to another Activity, a white screen is displayed for 2 seconds. I am using this code:

Intent intent = new Intent(this, SecondActivity.class);
startActivity(intent);

How can I resolve this issue?

Create a Theme like this:

<style name="YourTheme" parent="YourParentTheme">
    <item name="android:windowDisablePreview">true</item>
</style>

Apply this theme to your second activity

More detail in this link: http://www.tothenew.com/blog/disabling-the-preview-or-start-window-in-android/

If your activity contains more complex layouts, do not use finish() after setting flag. Use FLAG_ACTIVITY_CLEAR_TOP and _TASK instead and it will solve your problem.This worked for me perfectly

Intent intent = new Intent(this, SecondActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.l̥FLAG_ACTIVITY_CLEAR_TOP ); startActivity(intent);

or use simply like below

Intent intent = new Intent(this, SecondActivity.class); startActivity(intent);

While switching from ActivityOne to ActivityTwo, till ActivityTwo onCreate method gets executed default background is shown which is the white/black screen. Good practise is don't do heavy operation in onCreate. To fix the issue set transparent background to ActivityTwo as shown below.

<style name="YourTheme" parent="YourParentTheme">
<item name="android:windowBackground">@android:color/transparent</item>
</style>

In Manifest set above theme

<activity
            android:name=".ActivityTwo"
            android:theme="@style/YourTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
</activity>

Try adding intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); before calling startActivity(intent);

Intent intent = new Intent(this, SecondActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

If your activity contains more complex layouts/ contains large size background image it takes rendering, so only that white page is displaying. If you want to remove that time delay use low size png images and clear layout designs.

By using FLAG_ACTIVITY_NEW_TASK you are getting white screen, remove this like use this. It will work.

Intent intent = new Intent(this, SecondActivity.class);
startActivity(intent);

To go to next activity use flag

Intent intent = new Intent(this, SecondActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

尝试添加intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)

use finish if you want to clear the activity means when you press back then there is no stack of activity.

So you want to clear then use finish otherwise don't use it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM