FLAG_ACTIVITY_CLEAR_TOP in Android

Android

Android Problem Overview


Can somebody explain me in a really simple way what does FLAG_ACTIVITY_CLEAR_TOP mean? I know there were a lot of questions about it, but none of the answers satisfied me. Can somebody also give an example where this flag is useful? Thanks.

Android Solutions


Solution 1 - Android

Please check the below link for the details of the same:

http://developer.android.com/reference/android/content/Intent.html

What it means is: let's say you have 4 activities, A, B, C, and D, and the flow is

A -> B -> C -> D

and now when you are on D you want to start activity B (from the stack and not a new instance) then you can use this intent flag. Also what it does is remove all the other activities on top of B (here C and D).

A realtime example would be an email app with activities ReadMailInInbox -> OpenMailFullScreen -> ReplyMail once you reply to your mail you wont want to go back to OpenMailFullScreen rather you would want your ReadMailInInbox activity to come on top so you can start this activity by passing an intent with the flag set as FLAG_ACTIVITY_CLEAR_TOP.

Hope this helps.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionlomzaView Question on Stackoverflow
Solution 1 - AndroidDevaView Answer on Stackoverflow