5

I'm using flag FLAG_ACTIVITY_SINGLE_TOP and FLAG_ACTIVITY_CLEAR_TOP to go back to my previous "standard" activity. I use FLAG_ACTIVITY_SINGLE_TOP to prevent re-creating a new instance. But what I found is that the flag FLAG_ACTIVITY_SINGLE_TOP is neglected and the activity is finished and re-created.

  • Here is what I found in docs. FLAG_ACTIVITY_CLEAR_TOP: It says that you can add FLAG_ACTIVITY_SINGLE_TOP when using FLAG_ACTIVITY_CLEAR_TOP to prevent "finish - recreate".

  • Here is another doc. FLAG_ACTIVITY_CLEAR_TOP:

    Note: If the launch mode of the designated activity is "standard", it too is removed from the stack and a new instance is launched in its place to handle the incoming intent. That's because a new instance is always created for a new intent when the launch mode is "standard".

Did I misunderstand the first doc?

Alexander Farber
  • 21,519
  • 75
  • 241
  • 416
Derek Hsu
  • 1,158
  • 11
  • 15

3 Answers3

5

The documentation suggests that FLAG_ACTIVITY_CLEAR_TOP is all you need to set. But you actually HAVE to set both to prevent the activity from being created again.

This did the trick in my case: (Main being the activity that I wanted to return to)

  Intent tabIntent = new Intent(this, Main.class);
  tabIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
  startActivity(tabIntent);
Kris Van Bael
  • 2,842
  • 1
  • 18
  • 19
2

This one could be helpful: Android Intent.FLAG_ACTIVITY_SINGLE_TOP AND Intent.FLAG_ACTIVITY_CLEAR_TOP

Community
  • 1
  • 1
Moss
  • 6,002
  • 1
  • 35
  • 40
0

Check this one.
Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED|Intent.FLAG_ACTIVITY_SINGLE_TOP)

Mubarak
  • 1,419
  • 15
  • 22