swati
swati

Reputation: 1283

Difference between SingleTask and FLAG_ACTIVITY_CLEAR_TOP

I am trying to understand the difference between SingleTask and FLAG_ACTIVITY_CLEAR_TOP. It seems that both are working in the same manner. Ex- I created Activity A -> B -> c -> D -> E where launch mode of C is SingleTask. Now if I open C from E then on back press I get A -> B -> c The same thing happens when I launch C from E with FLAG_ACTIVITY_CLEAR_TOP. Not sure what is the difference between these two.

Upvotes: 2

Views: 836

Answers (1)

David Wasser
David Wasser

Reputation: 95618

If you set launchMode="singleTask" but do not also set taskAffinity on the <activity> then the launch mode is ignored. This is the reason that you see no difference in the behaviour.

If you set launchMode="singleTask" and taskAffinity="" on C and then have this task stack: A->B and then B launches C, you will end up with 2 separate tasks: One task has A->B and the other task contains C. If you were then to press the HOME button, you would see 2 tasks of your app in the list of recent tasks.

Upvotes: 5

Related Questions