19

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?

skrrgwasme
  • 9,358
  • 11
  • 54
  • 84
androidXXX
  • 191
  • 1
  • 1
  • 5

9 Answers9

35

Create a Theme like this:

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

Apply this theme to your second activity

Ziwei Zeng
  • 691
  • 5
  • 21
  • Worked for me too. Thank you. – 1lb3r Jul 30 '17 at 08:08
  • what this actually do? – Syed Raza Mehdi Feb 26 '18 at 11:42
  • 1
    Its delaying activity loading time. – Rohit Bandil Mar 06 '18 at 13:14
  • by adding that line its not taking one click to open the app . It's taking two clicks and after the second click it holds for 2 sec and launches the app – nethra gowda Apr 27 '18 at 09:03
  • What if I don't have an activity to implement the style? for example, when i just want to open a new browser from my app. When I back to my app i see the blank white screen.... Intent intent = new Intent(Intent.ActionView); intent.AddFlags(ActivityFlags.ClearTop); intent.SetData(Android.Net.Uri.Parse(url)); context.StartActivity(intent); Can you please help? – Omtechguy Sep 15 '20 at 04:27
  • @Omtechguy have you tried to apply this style to the first activity when you back to your app? – Ziwei Zeng Sep 15 '20 at 18:48
6

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

Sagar
  • 5,273
  • 4
  • 37
  • 50
5

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>
Rocky
  • 537
  • 4
  • 5
1

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);
Jas
  • 3,207
  • 2
  • 15
  • 45
1

Try to add intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)

Piyush
  • 18,895
  • 5
  • 32
  • 63
Nikhil bohra
  • 114
  • 1
  • 5
1

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.

Nandhu
  • 68
  • 11
1

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);
franklinsijo
  • 17,784
  • 4
  • 45
  • 63
Lovekush Vishwakarma
  • 3,035
  • 23
  • 25
0

To go to next activity use flag

Intent intent = new Intent(this, SecondActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Aditya Vyas-Lakhan
  • 13,409
  • 16
  • 61
  • 96
0

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.

Racil Hilan
  • 24,690
  • 13
  • 50
  • 55
Sam Patel
  • 1
  • 3