我的导航体系结构组件有两个导航流程:
A > B > C
和
A > X > C
在第一个流程中,popBackStack()
按预期工作。
但是我想要第二个流程中的其他行为。我不想弹出到 X片段,而是直接弹出到 A片段。
由于可以通过多种方式访问片段C ,因此无法在destinationId
中使用固定的popBackStack(destinationId,inclusive)
。
任何解决方案?可能是导航方向配置吗?
答案 0 :(得分:2)
将此操作用于x到c。
<fragment
android:id="@+id/x"
...
>
<action
android:id="@+id/action_X_to_C"
app:destination="@id/C"
app:popUpTo="@id/A" >
</action>
</fragment>
在FragmentX中
findNavController().navigate(R.id.action_x_to_C)