Reputation: 221
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
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
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
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
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
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
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
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
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