Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Navigation Component Backstack on self call

I am using the Android Navigation Component to handle the fragments.

I have Fragment A, B, C and E which can all open Fragment D (with a little different data).

On Fragment D you can then go either back or open another Fragment D with different data.

The user may click A->D->D->D->D->D and then back.

Is there a simple way to get back directly to A (or B, C, E whatever was the starting point) from D without going back all D calls?

I was hoping I could set parameters on the action arrows, but did not find any setting which worked.

enter image description here

like image 418
Gunnar Bernstein Avatar asked Dec 05 '25 03:12

Gunnar Bernstein


1 Answers

That's exactly what the "Single Top" option does: only allows a single copy of that destination on the top of the back stack.

<action android:id="@+id/action_nav_detail_self"
    app:destination="@id/nav_detail"
    app:launchSingleTop="true"/>
like image 51
ianhanniballake Avatar answered Dec 07 '25 19:12

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!