popUpTo & popUpToInclusive not working Android Navigation Components

553 views Asked by At

I am using Navigation Components to navigate between fragments. A is the startDestination and B is the home fragment. From A I can got to B and from B I can go to C, D, E and so on. I've added a global action to fragment B. Since, start destination is A, it is launched when the app starts. I am using global action to fragment B to navigate from A to B and I don't want the fragment to be on backstack but A shows up when I backpress from B.

Here is the global action to B:

<action
    android:id="@+id/action_global_to_B"
    app:destination="@id/B"
    app:popUpTo="@id/B"
    app:popUpToInclusive="true"/>

SO you can see I did both popUpTo, and popUpToInclusive to the global action. But I still see fragment A is still in backstack.

And then I tried this:

<fragment
android:id="@+id/A"
android:name="com.xx.A"
android:label="A" >
<action
    android:id="@+id/action_A_to_B"
    app:destination="@id/B"
    app:popUpTo="@id/B"
    app:popUpToInclusive="true"/>
</fragment>

Still the same issue.

1

There are 1 answers

0
EpicPandaForce On

Make it so:

<fragment android:id="@+id/A"
          android:name="com.xx.A"
          android:label="A">
    <action
        android:id="@+id/action_A_to_B"
        app:destination="@id/B"
        app:popUpTo="@id/A"
        app:popUpToInclusive="true"/>
</fragment>