6

I have read, http://developer.android.com/guide/components/tasks-and-back-stack.html and I have looked up the documentation for FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET, but I still do not understand why a employee at Google decided to include it in their blog post about sharing.

http://android-developers.blogspot.com/2012/02/share-with-intents.html

Here is their code snippet exactly:

Intent intent=new Intent(android.content.Intent.ACTION_SEND);
intent.setType("text/plain");
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);

// Add data to the intent, the receiving app will decide what to do with it.
intent.putExtra(Intent.EXTRA_SUBJECT, “Some Subject Line”);
intent.putExtra(Intent.EXTRA_TEXT, “Body of the message, woot!”);

The documentation says:

If set, this marks a point in the task's activity stack that should be cleared when the task is reset...

I am still very unsure of this flag. I'm not sure I can think of a reason to include it in my share() method, but if Google used it in a blog post, then I'm sure they know of a scenario where this comes into play. Thanks in advance.

EGHDK
  • 17,818
  • 45
  • 129
  • 204

2 Answers2

9

The article explains it in the first code sample:

This flag clears the called app from the activity stack, so users arrive in the expected place next time this application is restarted.

If you leave out the flag, when returning to your app (from homescreen, from recents etc.), you would see the Activity of the share target (messaging/mailing/IM app) instead of yours. Try it and you will see the difference.

molnarm
  • 9,856
  • 2
  • 42
  • 60
5

enter image description here

This flag marks the called activity and all activities put on top of it to be cleared (removed from the stack) when the task is reset. This reset is performed as soon as the task is brought to the foreground using FLAG_ACTIVITY_RESET_TASK_IF_NEEDED, which is always set by the system when the user resumes a task from the home screen, the main menu or the list of recently started activites.

You can use this to define a point in the task stack from where all started activities should be “forgotten” once the task is sent to the background.

MORE : SEE HERE