Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kill fragment in navigation controller

My flow of fragment is like this

Main -> A -> B -> C ->A

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.

In fragment C, I use this

 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>
like image 849
John Joe Avatar asked Dec 17 '22 16:12

John Joe


1 Answers

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

like image 120
Alex H Avatar answered Dec 21 '22 09:12

Alex H