在导航控制器中杀死片段

Joh*_*Joe 2 navigation android fragment navigationcontroller kotlin

我的片段流是这样的

Main -> A -> B -> C ->A
Run Code Online (Sandbox Code Playgroud)

在片段c中,它具有一个提交按钮,该按钮将返回到A。当我在A中按下后退按钮时,我希望它返回到Main。但是它返回片段c。

在片段C中,我使用了

 findNavController().navigate(R.id.action_c_to_a)
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

Ale*_*x H 6

Why not pop up to fragment A? You could just call findNavController().popBackStack(R.id.fragmentA, false) instead of navigating with an action.