0

I have activity with container like this:

    <fragment
        android:id="@+id/nav_host_container"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:defaultNavHost="true"
        app:navGraph="@navigation/my-graph-name" />

My activity is also configured like this:

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        NavigationUI.setupActionBarWithNavController(
            this,
            findNavController(R.id.nav_host_container)
        )
    }

    override fun onSupportNavigateUp(): Boolean {
        return findNavController(R.id.nav_host_container).navigateUp()
    }

My graph has startDestination a fragment with action:

        <action
            android:id="@+id/action1"
            app:popUpTo="@+id/my1stFragment"
            app:popUpToInclusive="true"
            app:destination="@+id/my2ndFragment" />

Q.: why when I tap my2ndfragment toolbar's "up" button, my graph basically starts from beginning? I would expect such action to close activity.

ror
  • 3,295
  • 1
  • 19
  • 27

1 Answers1

0

According to the Android documentation:

If a user is at the app's start destination, then the Up button does not appear, because the Up button never exits the app. The Back button, however, is shown and does exit the app.

When your app is launched using a deep link on another app's task, Up transitions users back to your app’s task and through a simulated back stack and not to the app that triggered the deep link. The Back button, however, does take you back to the other app.

Marco RS
  • 8,145
  • 3
  • 37
  • 45
  • Sorry I took some time to digest this but I still don't understand how it helps my case. – ror Dec 04 '19 at 08:01
  • The documentation is basically saying that you are seeing the desired behavior. The up button should not leave the app. If you are wanting it to close the current activity then youd probably have to instead navigate to another graph or call `finish()` on the activity yourself. – Marco RS Dec 04 '19 at 18:02