White screen is displayed while switching between Activities
Asked Answered
R

9

22

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?

Ricarda answered 16/10, 2015 at 4:18 Comment(3)
show your second activity xml and java file.Winther
Do you have any web services in SecondActivity?Balliett
Amsheer : No server calls. FirstActivity has MoodStock Scanner Camera. Second Activity contains just one Text "hello world".Ricarda
E
36

Create a Theme like this:

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

Apply this theme to your second activity

Expensive answered 14/6, 2017 at 19:29 Comment(6)
Worked for me too. Thank you.Greasepaint
what this actually do?Contraction
Its delaying activity loading time.Roncesvalles
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 appMountainside
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?Hasp
@Hasp have you tried to apply this style to the first activity when you back to your app?Expensive
A
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);

Alemanni answered 16/12, 2016 at 6:50 Comment(1)
Unfortunately it doesn't finish your current activity.Determinant
F
6

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>
Fonsie answered 6/2, 2018 at 11:6 Comment(0)
J
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);
Job answered 16/10, 2015 at 4:20 Comment(0)
B
1

Try to add intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)

Bedazzle answered 16/10, 2015 at 5:17 Comment(0)
G
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.

Gerrald answered 16/10, 2015 at 8:46 Comment(0)
B
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);
Bufford answered 2/2, 2017 at 17:58 Comment(0)
D
0

To go to next activity use flag

Intent intent = new Intent(this, SecondActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Decretal answered 16/10, 2015 at 5:2 Comment(5)
what's the intent of finish()?Infringement
to finish() current activityDecretal
I dont want to finish my current(first) activity.Ricarda
ok then show your full code..have you added your set conttentview to your second activity?Decretal
sometimes only using this will not work..so better try Youractivityname.this or getApplicationContextDecretal
Z
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.

Zooid answered 16/10, 2015 at 6:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.