gpt4 book ai didi

安卓导航组件 : how save fragment state

转载 作者:太空宇宙 更新时间:2023-11-03 13:39:41 26 4
gpt4 key购买 nike

我使用 bottomNavigationView 和导航组件。请告诉我如何在切换到另一个选项卡并返回到旧选项卡后不破坏 fragment ?例如,我有三个选项卡 - A、B、C。我的起始选项卡是 A。导航到 B 后,然后返回 A。当我返回到选项卡 A 时,我不希望重新创建它。怎么做?谢谢

最佳答案

根据 open issue , Navigation 不直接支持多个返回堆栈 - 即,当您从 A 或 C 返回 B 时保存堆栈 B 的状态,因为 Fragments 不支持多个返回堆栈。

根据 this comment :

The NavigationAdvancedSample is now available at https://github.com/googlesamples/android-architecture-components/tree/master/NavigationAdvancedSample

This sample uses multiple NavHostFragments, one for each bottom navigation tab, to work around the current limitations of the Fragment API in supporting multiple back stacks.

We'll be proceeding with the Fragment API to support multiple back stacks and the Navigation API to plug into it once created, which will remove the need for anything like the NavigationExtensions.kt file. We'll continue to use this issue to track that work.

因此,您现在可以在您的应用中使用 NavigationAdvancedSample 方法并为问题加注星标,以便在解决潜在问题并向 Navigation 添加直接支持时获得更新。

关于安卓导航组件 : how save fragment state,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56195791/

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