Reputation: 4292
A white screen blinks for few milliseconds when I simply go from login activity to Main activity with following clear back stack code.
Intent intent = new Intent(LoginActivity.this, HomeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
overridePendingTransition(0, 0);
If I just make the startActivity without Flags (or say without clear backstack)
overridePendingTransition(0, 0);
It doesn't blink with white screen.
But I have to clear back stack and start a new activity with NO transition animation. So it doesn't blink/appear in white screen for few milliseconds.
Looking forward to get a perfect answer soon. Cheers !
Upvotes: 1
Views: 1217
Reputation: 4292
As I have mentioned in the question that startActivity without using flags makes no blink and showing white screen.
So I choose that.
Now the problem is to clear the stack of 1st Login activity when I am into Main Activity.
I resolved it by setting the context of Login activity into Application class using setter and getter method.
And Whenever You reached to Main Activity. It will check whether you have the context in Application class by getter method.
If it's a yes and is a login activity then make the context.finish which will clear the back-stack by removing the login activity from Main Activity. And set null value to setter in Application class.
Feel free to share any concern regarding this. Thank you.
Upvotes: 0
Reputation: 2958
Don't use Intent.FLAG_ACTIVITY_NEW_TASK
. If you want to clear the backstack (and assuming your login Activity
is the only one in the stack), just finish
the current Activity:
Intent intent = new Intent(LoginActivity.this, HomeActivity.class);
startActivity(intent);
overridePendingTransition(0, 0);
finish();
Intent.FLAG_ACTIVITY_NEW_TASK
is likely the cause of the flash since it requires you to create a whole new "task" (which is a collection of Activities with a given history) rather than just reusing the current one. It's almost like navigating to another app at that point.
Upvotes: 0
Reputation: 106
Try setting noHistory="true"
for login activity in the manifest and start HomeActivity
without any flags. This should solve your problem.
Upvotes: 2