0

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.

Alex Sullivan
  • 562
  • 7
  • 20
  • possible duplicate of [Intent.FLAG\_ACTIVITY\_CLEAR\_TOP not working](http://stackoverflow.com/questions/23062130/intent-flag-activity-clear-top-not-working) – dy_ Mar 09 '15 at 14:31

2 Answers2

0

try these flags:

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
dy_
  • 2,433
  • 24
  • 27
  • The no_history flag looked promising - but that looks like it's used to start a new activity and not add it to the stack. That's not what I want. The login portion of my app has a few activities that you may want to navigate around, so I can't use this flag for them. Using it on my main app activity doesn't make much sense it I obviously want it to be on the stack. – Alex Sullivan Mar 09 '15 at 15:46
  • Also like I said the clear_top/new_task flags have not helped me. – Alex Sullivan Mar 09 '15 at 15:46
  • maybe have a look at the accepted answer to [this question](http://stackoverflow.com/questions/12403364/clear-activity-stack-and-start-new-activity-in-android). looks a bit hacky, but it seems to work. – dy_ Mar 10 '15 at 16:35
0

Use this

   intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
Shadow
  • 6,864
  • 6
  • 44
  • 93
  • I don't understand how the single_top flag would help in this situation. The google docs say "If set, the activity will not be launched if it is already running at the top of the history stack.". – Alex Sullivan Mar 09 '15 at 15:45