FLAG_ACTIVITY_CLEAR_TOP not working on 5.0+ device

2019-09-19 01:36发布

I use the FLAG_ACTIVITY_CLEAR_TOP intent flag to clear the stack when transitioning from a login activity to the main app - everything works perfectly in 4.x devices, but on lollipop it's not working. Just to add some code, here's what I'm calling:

Intent intent = new Intent(this, MyActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

I've tried using the FLAG_ACTIVITY_NEW_TASK flag in conjunction but that also hasn't helped.

2条回答
何必那么认真
2楼-- · 2019-09-19 02:23

Use this

   intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
查看更多
干净又极端
3楼-- · 2019-09-19 02:26

try these flags:

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
查看更多
登录 后发表回答