If I have 4 fragments (A,B,C and D) and I move from left to right to end at D, I want to clear back the stack till A.
so when using navigation graph, it may be in the action of C fragment like so:
<action
android:id="@+id/c"
app:destination="@+id/d"
app:popUpTo="@id/a"
app:popUpToInclusive="true" />
but when am doing this, the c fragment is not cleared from backstack. It means that when I click backpress from d, c is coming and then a. How do I solve this please?
To achieve A->B->C->D
and then pressing back return to A
:
Define in your navigation:
<fragment
android:id="@+id/c"
...>
<action
android:id="@+id/action_c_to_d"
app:destination="@id/d"
app:popUpTo="@+id/b"
app:popUpToInclusive="true"/>
</fragment>
And use:
findNavController().navigate(R.id.action_c_to_d)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.