Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to navigate fragment without adding it into backstack with NavController?

NavController has methods navigate which navigate by default with backstack. How to navigate to the fragment without having backstack? Please note that, I am not asking about FragmentTransaction

like image 555
Farrux Bahodirov Avatar asked Jun 19 '26 06:06

Farrux Bahodirov


1 Answers

If you have a back stack of:

A -> B

And want to get to a back stack of

A -> C

You can do a 'replace' operation by popping B off the back stack and adding C.

In Navigation, this is done by using app:popUpTo (and optionally app:popUpToInclusive="true" if needed) to the <action> in your XML or by using the equivalent NavOptions API.

<action
  android:id="@+id/goToC"
  app:destination="@+id/c"
  app:popUpTo="@+id/b"
  app:popUpToInclusive="true"/>
like image 119
ianhanniballake Avatar answered Jun 21 '26 19:06

ianhanniballake



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!