gpt4 book ai didi

android - android noHistory 和 android FLAG_ACTIVITY_CLEAR_TASK 之间有什么区别

转载 作者:搜寻专家 更新时间:2023-11-01 09:37:37 28 4
gpt4 key购买 nike

何时使用 android:noHistory 以及何时使用 Intent FLAG_ACTIVITY_CLEAR_TASK?在我的场景中,当我想从 Activity B 到 Activity C 时,我想清除包含 Activity A 的后台堆栈?那么我应该使用 noHistory 还是 FLAG_ACTIVITY_CLEAR_TASK?

最佳答案

来自 Android 开发者文档:

FLAG_ACTIVITY_NO_HISTORY

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_HISTORYnoHistory 将确保新 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com