Reputation: 3101
My Application Flow:
Login->Profile->UpdateProfile->ChangePass
All of my activitys extends FragmentActivity
When I press button in ChangePass Activity I call this code:
Intent intent=new Intent(getApplicationContext(),LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
So It should start LoginActivity and when I press back from LoginActivity then Application should close...But When I press back button from Login Activity the flow is:
ChangePass->UpdateProfile->Profile->Login
Why My back stack is not cleared ?
Note:
I have applied all these solutions but not working: 1.link 2.link
Upvotes: 6
Views: 7714
Reputation: 469
Clear the task and create new.
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)
This might create a temporary white screen while transition. To remove this defect. Add this to your App theme.
<item name="android:windowDisablePreview">true</item>
Enjoy Android!
Upvotes: 0
Reputation: 3624
Very late reply though.
But might help others as it worked for me.
Developers sometimes confuse FLAG_ACTIVITY_CLEAR_TASK
with FLAG_ACTIVITY_CLEAR_TOP
Use this instead
intentRestart.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
Upvotes: 4
Reputation: 1125
Instead of replacing the old flags try appending one. Setflag replace theold flags.
Try using addFlags.
Upvotes: 0
Reputation: 23354
Try the following way -
Intent intent = new Intent(getActivity(), LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
finish();
For more alternatives and details check intent-flag-activity-clear-top-doesn't-deletes-the-activity-stack. The post explains with the result code perfectly and with the above solution.
Upvotes: 2