Search code examples
androidandroid-navigationandroidx

AndroidX navigation navigateUp twice


I am using the new AndroidX navigation framework.

I have a few fragments all linked in a navigation chain.

FragmentA --> FragmentB --> FragmentC

FragmentC has a Cancel button that should send me up all the way back to FragmentA.

Should I do the following:
on FragmentC call the method:

 Navigation.findNavController(view).navigateUp();

then on FragmentB listen to some callback and using some passed parameter or argument trigger another navigateUp() function from FragmentB

or is there some method that will do the equivalent of navigateUpTwice()


Solution

  • What I ended up doing was

    Navigation.findNavController(view).popBackStack(R.id.fragmant_a,false)