Intent.FLAG_ACTIVITY_CLEAR_TOP not working

半腔热情 提交于 2019-12-06 03:44:09

问题


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 instead
intentRestart.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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!