问题
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
回答1:
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 insteadintentRestart.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
回答2:
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.
回答3:
Instead of replacing the old flags try appending one. Setflag replace theold flags.
Try using addFlags.
来源:https://stackoverflow.com/questions/23062130/intent-flag-activity-clear-top-not-working