androidXXX
androidXXX

Reputation: 221

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?

Upvotes: 22

Views: 19762

Answers (9)

Ziwei Zeng
Ziwei Zeng

Reputation: 701

Create a Theme like this:

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

Apply this theme to your second activity

Upvotes: 36

Rocky
Rocky

Reputation: 547

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>

Upvotes: 6

Sagar H
Sagar H

Reputation: 5541

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

Upvotes: 6

Lovekush Vishwakarma
Lovekush Vishwakarma

Reputation: 3179

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

Upvotes: 1

Sam Patel
Sam Patel

Reputation: 1

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.

Upvotes: 0

Aditya Vyas-Lakhan
Aditya Vyas-Lakhan

Reputation: 13555

To go to next activity use flag

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

Upvotes: 0

Nandhu
Nandhu

Reputation: 68

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.

Upvotes: 1

Nikhil bohra
Nikhil bohra

Reputation: 114

Try to add intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)

Upvotes: 1

Jas
Jas

Reputation: 3212

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

Upvotes: 1

Related Questions