在导航控制器中杀死片段 [英] Kill fragment in navigation controller
本文介绍了在导航控制器中杀死片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的片段流是这样的
Main -> A -> B -> C ->A
在片段c中,它具有一个提交按钮,该按钮将返回到A.当我按A中的后退按钮时,我希望它返回到Main.但是它返回片段c.
In fragment c, it has a submit button which will return to A. When I press back button in A, I want it back to Main. But it return to fragment c instead.
在片段C中,我使用此
findNavController().navigate(R.id.action_c_to_a)
nav_graph.xml
<fragment
android:id="@+id/fragmentC"
android:name="xxx"
android:label="xxx">
<action
app:launchSingleTop="true"
app:popUpTo="@+id/fragmentA"
app:popUpToInclusive="true"
android:id="@+id/action_c_to_a"
app:destination="@id/fragmentA" />
</fragment>
推荐答案
为什么不弹出片段A?您可以只调用 findNavController().popBackStack(R.id.fragmentA,false)
而不是进行操作.
Why not pop up to fragment A? You could just call findNavController().popBackStack(R.id.fragmentA, false)
instead of navigating with an action.
这篇关于在导航控制器中杀死片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文