gpt4 book ai didi

android - 是否有与 SINGLE_TOP 标志等效的 fragment ?

转载 作者:太空狗 更新时间:2023-10-29 14:16:22 32 4
gpt4 key购买 nike

我有一个应用程序可以在用户导航时替换容器中的 fragment 。 (如果您开始一个选择了微调器导航的新项目,最初基于 android studio 创建的方法)

我希望用户能够按后退按钮返回到之前的页面,但不必按一百万次后退按钮来退出应用。

我可以将 fragment 添加到后台堆栈,但这意味着可能会有一个巨大的堆栈,或者我必须手动找到最后一个实例并清除堆栈的一部分。如果我使用 Activity ,我可以使用 SINGLE_TOP 标志启动我的 Intent 。替换 fragment 时是否可以使用等效方法?

最佳答案

有一个名为 Android navigation component 的新 Android Jetpack 组件这将帮助您达到预期的目标。这里有个好tutorial在上面您还可以找到 SingleTop 的用法。 This article描述了与您的用例相关的一行。

The app:launchSingleTop is used whether navigation action should launch as single-top (i.e., there will be at most one copy of a given destination on the top of the back stack). This functions similarly to how android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP works with activities.

关于android - 是否有与 SINGLE_TOP 标志等效的 fragment ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21615261/

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