避免使用导航架构组件弹出到特定片段

Avoid to popback to specific fragment with Navigation Architecture Component

我有两个带有导航架构组件的导航流:

A > B > C

A > X > C

在第一个流程中,popBackStack() 按预期工作。 但我想在第二个流程中有不同的行为。我不想弹出回 Fragment X 而是直接弹出到 Fragment A.

因为 片段 C 可以通过多种方式访问​​,所以我不能在 popBackStack(destinationId,inclusive).

中使用固定的 destinationId

有什么解决办法吗?可能是导航方向配置?

对 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>

在片段X中

findNavController().navigate(R.id.action_x_to_C)