FLAG_ACTIVITY_CLEAR_TOP not working on 5.0+ device

2019-09-19 02:03发布

问题:

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.

回答1:

try these flags:

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);


回答2:

Use this

   intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);