0

I am using navigation architecture component in my application.

Suppose I have fragment A as start destination. I have push fragment B and Fragment C via navigation controller.

My navigation back stack is A-> B-> C.

Then I navigate to Fragment A with below action

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

Now My navigation back stack should be A.

But if check parentFragmentManager.fragments back stack is A->A

Also the swipeBackDismiss of activity is not working.

my navigation.xml file

<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/nav_graph">

    <fragment
        android:id="@+id/FirstFragment"
        android:name="com.example.wearexample1.FirstFragment"
        android:label="@string/first_fragment_label"
        tools:layout="@layout/fragment_first">

        <action
            android:id="@+id/action_FirstFragment_to_SecondFragment"
            app:destination="@id/SecondFragment" />
    </fragment>
    <fragment
        android:id="@+id/SecondFragment"
        android:name="com.example.wearexample1.SecondFragment"
        android:label="@string/second_fragment_label"
        tools:layout="@layout/fragment_second">
    </fragment>

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

</navigation>
dev
  • 16
  • 2
  • You mean you go to A from C? – Sam Chen Aug 04 '21 at 21:47
  • yes, I navigate from C to A. – dev Aug 09 '21 at 16:32
  • From C to A using action instead of back key, right? Then according to your current setup, it's normal behavior. What's your expectation? – Sam Chen Aug 09 '21 at 16:46
  • with `app:popUpTo="@id/fragment_a"` `app:popUpToInclusive="true"` old instance of fragment A should be removed and fragments stack should be A. my expected behavior is that the fragment stack when i go from C to A should be just A. – dev Aug 09 '21 at 17:30
  • And what do you get now? – Sam Chen Aug 09 '21 at 17:40
  • now i am getting A->A – dev Aug 09 '21 at 17:59
  • I don't understand what is "A->A". Can you describe more detailly. – Sam Chen Aug 09 '21 at 18:20
  • parentFragmentManager.fragments is returning list of fragments as [Fragment A, Fragment A] but the expected result is [Fragment A]. as i have pop the fragment till A( Inclusive) using `app:popUpTo="@id/fragment_a"` `app:popUpToInclusive="true"` – dev Aug 09 '21 at 18:28
  • Post your `navigation` file. I did this before but with no problem: https://youtu.be/LNyk_FEkZoA. – Sam Chen Aug 09 '21 at 19:08
  • @SamChen i have updated my navigation file – dev Aug 10 '21 at 09:03
  • That's weird, you have the same setup as me: https://stackoverflow.com/a/65723391/3466808. – Sam Chen Aug 10 '21 at 12:38

0 Answers0