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?
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
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);
Try to add intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
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);
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.
© 2022 - 2024 — McMap. All rights reserved.