android - 共享时 "FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET"的作用是什么?

标签 android android-intent back-stack android-sharing

我已阅读,http://developer.android.com/guide/components/tasks-and-back-stack.html我已经查阅了FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET 的文档,但我仍然不明白为什么 Google 的一名员工决定将其包含在他们关于共享的博客文章中。

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

这是他们的代码 fragment :

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!”);

文档说:

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

我对这个标志仍然很不确定。我不确定我能想到将它包含在我的 share() 方法中的原因,但如果 Google 在博客文章中使用它,那么我确信他们知道它发挥作用的场景。提前致谢。

最佳答案

文章在第一个代码示例中对其进行了解释:

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

如果您省略标志,当返回到您的应用程序时(从主屏幕、最近等),您会看到共享目标(消息/邮件/IM 应用程序)的 Activity你的。尝试一下,您会发现不同之处。

关于android - 共享时 "FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET"的作用是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21231807/

相关文章:

android - DialogFragment - 设置初始值并在旋转后保持状态

android - 比较两个数组列表元素并获取不常见的元素

java - Android - 获取传感器横向方向

android.os.FileUriExposedException : file:///storage/emulated/0/Pictures/picFolder/1. jpg 通过 ClipData.Item.getUri() 暴露在应用程序之外

android - 从 fragment 进入新 Activity 并返回时 fragment Activity 被破坏

ios - 在转换时清除返回堆栈

java - 我无法使用 zxing 读取翻转垂直二维码

android - 如何在android中打开系统数据使用 Activity ?

android - 如何使用四个 (x,y) 坐标裁剪图像

android - 如何从 BackStack 恢复现有的 Fragment