- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
何时使用 android:noHistory 以及何时使用 Intent FLAG_ACTIVITY_CLEAR_TASK?在我的场景中,当我想从 Activity B 到 Activity C 时,我想清除包含 Activity A 的后台堆栈?那么我应该使用 noHistory 还是 FLAG_ACTIVITY_CLEAR_TASK?
最佳答案
来自 Android 开发者文档:
If set, the new activity is not kept in the history stack. As soon as the user navigates away from it, the activity is finished. This may also be set with the
noHistory
attribute.
FLAG_ACTIVITY_CLEAR_TASK
,但是,执行不同的角色:
If set in an Intent passed to Context.startActivity(), this flag will cause any existing task that would be associated with the activity to be cleared before the activity is started. That is, the activity becomes the new root of an otherwise empty task, and any old activities are finished. This can only be used in conjunction with FLAG_ACTIVITY_NEW_TASK.
总而言之,使用 FLAG_ACTIVITY_NO_HISTORY
或 noHistory
将确保新 Activity 不会添加到历史堆栈(从而在弹出后续 View 时跳过它),而 FLAG_ACTIVITY_CLEAR_TASK
将导致在 Activity 开始之前清除与该 Activity 关联的任何现有任务。
因此在您的用例中,您希望对 Activity A 使用 FLAG_ACTIVITY_NO_HISTORY
,这将确保它不会被添加到返回堆栈。
关于android - android noHistory 和 android FLAG_ACTIVITY_CLEAR_TASK 之间有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41907078/
我有一个带有“连接 Facebook”登录按钮的典型初始屏幕。当用户触发 facebook 身份验证时,facebook 应用程序弹出,然后返回启动画面,以便在 onComplete() facebo
android:noHistory="true"请求权限时关闭 Activity 如何避免在请求权限时关闭 Activity ? 最佳答案 删除 Manifest 文件中的 android:noHis
我进退两难。我正在开发一个显示欢迎页面并要求用户注册或登录的应用程序。用户可以通过向上插入符号按钮和电话的后退按钮从注册/登录 Activity 到主要 Activity (欢迎页面)。 但是一旦用户
我遵循下一个流程,启动 Activity A(加载资源),然后转到 Activity B(登录)。我将 Activity A 标记为 noHistory = "true"并且在我开始 Activity
我一直在寻找一种从历史堆栈中删除特定 Activity 的方法,并找到了解决方案 here (Wakkas's anwer) .但是,如果我在打开此 Activity 的情况下关闭应用程序,例如通过按
android:noHistory true 的值意味着用户将无法返回到它。 所以 OnActivityResult 方法没有调用。我想使用该方法从手机存储中获取 uri。所以必须使用 OnActiv
我正在使用来自已将 android:noHistory 设置为“true”的第三方库的 Activity 。我是否可以在启动 Activity 之前在代码中覆盖该值? 我可以在 Intent 中使用与
我有一个应用程序,可以在用户第一次使用该应用程序时向其显示个人资料编辑屏幕。在编辑个人资料 Activity 中,我需要允许用户创建个人资料图像,捕捉图像或从图库中选择。 我希望能够捕获 OnActi
这两个属性有什么关系?如果我有 android:noHistory="true",那么有 android:finishOnTaskLaunch="true" 有什么意义吗? 最佳答案 假设您的应用中有
我已经为 list 上的 Activity 设置了 noHistory="true"。预期结果是当用户离开 Activity 并且它在屏幕上不再可见时,Activity 将完成。 当我按主页按钮导航到
我不希望我的应用程序在按下 back 按钮时显示很少的 Activity(比如 SplashScreenActivity)。因此,我在 Manifest.xml 中为该 Activity 使用了 no
假设我有一个带有菜单的基本 Activity ,当我单击菜单项 A 时,它会转到 Activity A。我再次打开菜单,然后转到 B。从 B 我回到 A,然后返回第四个暂时就这样。 所以堆栈将是 A,
我已经在 Internet 上阅读了有关此主题的信息,但我还没有找到解决方案。 list 文件中的解决方案如 :noHistory="true"。我想要的是,在用户单击 AddNewItem 类中的保
何时使用 android:noHistory 以及何时使用 Intent FLAG_ACTIVITY_CLEAR_TASK?在我的场景中,当我想从 Activity B 到 Activity C 时,
注意:存在一些混淆,所以让我澄清一下,我是在询问如何在 Windows Phone 7 中实现某些功能,方法是将它与 Android 中的类似功能进行比较。 问题: 了解 Windows Phone
我将属性 noHistory=true 用于我不想保留在后台堆栈中的 Activity 。它在 Android 2.3.3 上工作正常但在 4.0.3 上有一个奇怪的行为。当屏幕进入休眠状态而我将其唤
我正在开发一个视频通话应用程序,我有一个“来电”屏幕,当有人调用他们时会提醒用户。此屏幕是由传入的 GCM 触发的 Activity ,并在 list 中设置了 noHistory="true"和 s
我是一名优秀的程序员,十分优秀!