Can't set FLAG_ACTIVITY_SINGLE_TOP and FLAG_ACTIVITY_CLEAR_TOP in the same intent?

I use the FLAG_ACTIVITY_SINGLE_TOP and FLAG_ACTIVITY_CLEAR_TOP flag to return to the previous "standard" activity. I use FLAG_ACTIVITY_SINGLE_TOP to prevent the re-creation of a new instance. But I found that the FLAG_ACTIVITY_SINGLE_TOP flag FLAG_ACTIVITY_SINGLE_TOP ignored, and the action completes and is recreated.

  • Here is what I found in the docs. FLAG_ACTIVITY_CLEAR_TOP : it says that you can add FLAG_ACTIVITY_SINGLE_TOP when using FLAG_ACTIVITY_CLEAR_TOP to prevent "completion - re-creation".

  • Here is another document. FLAG_ACTIVITY_CLEAR_TOP :

    Note. If the launch mode of the specified action is "standard", it is also removed from the stack, and a new instance is launched instead to process the incoming intent. This is because a new instance is always created for a new intention when the startup mode is "standard".

Did I misunderstand the first document?

+4
source share
3 answers

The documentation states that FLAG_ACTIVITY_CLEAR_TOP is all you need to set. But you really have to set both to prevent the re-creation of activity.

This did the trick in my case: (The main one was the activity 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); 
+5
source

Check this. Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_SINGLE_TOP)

0
source

Source: https://habr.com/ru/post/1347549/


All Articles