我们已经在此处所述实施了底部导航:
我们使用的是导航版本2.4.1,该版本支持包装盒的多个背包。这样可以节省碎片状态,从而从主片段导航a - > b - > c - > b使用底部NAV,返回后保存片段B的状态B。这是预期的和要求的行为。
但是,对于我们底部NAV菜单中的片段之一,我希望有可能不保存状态。这是由于使用对讲时导航时某种令人困惑的行为。导航框架中有没有办法设置标志以不为单个片段保存状态?或其他任何方法可以通过在片段ondestroy/onResume或类似的片段中重置UI元素来“手动”进行编程清除保存的拯救状态?
We have implemented bottom navigation as described here:
https://developer.android.com/guide/navigation/navigation-ui#bottom_navigation
https://medium.com/androiddevelopers/navigation-multiple-back-stacks-6c67ba41952f
We are using navigation version 2.4.1, which supports multiple backstacks out of the box. This saves fragment state so that in navigating from main fragment A -> B -> C -> B using the bottomnav, state of fragment B is saved and restored upon return. This is as intended and much requested behaviour.
However, for one of the fragments in our bottomnav menu, I would like the possibility to NOT save the state. This is due to some confusing behaviour when navigating using talkback. Is there a way in the navigation framework to set a flag to not save state for a single fragment? Or any other way to programmatically clear savedstate without actually doing so "manually" by resetting the UI elements in fragment onDestroy/onResume or similar?
发布评论
评论(1)
我所做的只是使用相同的
androidx.navigation.ui.navigationui.setupwithnavcontroller
逻辑,但要更改我用例的Savestate和其他逻辑。您可以在导航到一个特定片段时将其应用。What I did was just use the same
androidx.navigation.ui.NavigationUI.setupWithNavController
logic but change the saveState and other logic specific to my use case. You could apply this when navigating to one specific fragment.