Fixed
Status Update
Comments
il...@google.com <il...@google.com>
da...@gmail.com <da...@gmail.com> #2
I'd like to add that this automatic removal of the NavGraph at the top of the stack is also making it hard for me to implement proper lateral top-level navigation.
A practical case where this kind of navigation happens is with a Material Design bottom navigation bar, where I have a NavHost above the bottom bar.
Given this navigation scheme:
A - B (top-level)
B1 (first sub-level)
When starting the Activity, the back stack is
0. A
1. NavGraph
If I wanted to navigate to B laterally, I would do:
navController.popBackStack(R.id.navGraph, false)
navController.navigate(R.id.B)
But the resulting back stack is:
0. B
Now, navigating between top-level destinations actually works (though popBackStack returns false); the problem arises again if I navigate to B1:
0. B1
1. B
When navigating from B1 to a top-level destination like A, the stack becomes:
0. A
1. B1
2. B
That is, A is not a top-level destination in the back stack: if I press back from A, I intend to exit the app, but I'm taken back to B1.
It would be nice to have a fixed reference to the bottom of the stack. Right now I'm working around this with a horrible ` while (navController.popBackStack()) continue`.
A practical case where this kind of navigation happens is with a Material Design bottom navigation bar, where I have a NavHost above the bottom bar.
Given this navigation scheme:
A - B (top-level)
B1 (first sub-level)
When starting the Activity, the back stack is
0. A
1. NavGraph
If I wanted to navigate to B laterally, I would do:
navController.popBackStack(R.id.navGraph, false)
navController.navigate(R.id.B)
But the resulting back stack is:
0. B
Now, navigating between top-level destinations actually works (though popBackStack returns false); the problem arises again if I navigate to B1:
0. B1
1. B
When navigating from B1 to a top-level destination like A, the stack becomes:
0. A
1. B1
2. B
That is, A is not a top-level destination in the back stack: if I press back from A, I intend to exit the app, but I'm taken back to B1.
It would be nice to have a fixed reference to the bottom of the stack. Right now I'm working around this with a horrible ` while (navController.popBackStack()) continue`.
il...@google.com <il...@google.com>
il...@google.com <il...@google.com> #3
Is this going to be fixed?
I have the same issue with a setup as follows:
Navigation graph.
<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 "
app:startDestination="@+id/startupGraph">
<navigation
android:id="@+id/startupGraph"
app:startDestination="@id/launcher_home">
<fragment
android:id="@+id/launcher_home"
android:name="com.example.android.codelabs.navigation.MainFragment"
android:label="@string/home"
tools:layout="@layout/main_fragment" />
</navigation>
<navigation
android:id="@+id/homeGraph"
app:startDestination="@id/flow_step_one">
<fragment
android:id="@+id/flow_step_one"
android:name="com.example.android.codelabs.navigation.FlowStepOneFragment"
tools:layout="@layout/flow_step_one_fragment" />
<fragment
android:id="@+id/flow_step_two"
android:name="com.example.android.codelabs.navigation.FlowStepTwoFragment"
tools:layout="@layout/flow_step_two_fragment" />
</navigation>
</navigation>
MainFragment.
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
view.findViewById<Button>(R.id.navigate_dest_bt).setOnClickListener{
Navigation.findNavController(it)
.navigate(R.id.homeGraph, null, NavOptions.Builder()
.setPopUpTo(R.id.startupGraph, false)
.build())
}
}
FlowStepOneFragment.
view.findViewById<View>(R.id.next_button).setOnClickListener {
Navigation.findNavController(it)
.navigate(R.id.flow_step_two, null, NavOptions.Builder()
.setPopUpTo(R.id.flow_step_one, true)
.build())
}
}
}
Causes the following error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.codelabs.navigation, PID: 12579
java.lang.IllegalArgumentException: Navigator androidx.navigation.fragment.FragmentNavigator@d70ec6f reported navigation to unknown destination id com.example.android.codelabs.navigation:id/flow_step_two
I have the same issue with a setup as follows:
Navigation graph.
<navigation xmlns:android="
xmlns:app="
xmlns:tools="
app:startDestination="@+id/startupGraph">
<navigation
android:id="@+id/startupGraph"
app:startDestination="@id/launcher_home">
<fragment
android:id="@+id/launcher_home"
android:name="com.example.android.codelabs.navigation.MainFragment"
android:label="@string/home"
tools:layout="@layout/main_fragment" />
</navigation>
<navigation
android:id="@+id/homeGraph"
app:startDestination="@id/flow_step_one">
<fragment
android:id="@+id/flow_step_one"
android:name="com.example.android.codelabs.navigation.FlowStepOneFragment"
tools:layout="@layout/flow_step_one_fragment" />
<fragment
android:id="@+id/flow_step_two"
android:name="com.example.android.codelabs.navigation.FlowStepTwoFragment"
tools:layout="@layout/flow_step_two_fragment" />
</navigation>
</navigation>
MainFragment.
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
view.findViewById<Button>(R.id.navigate_dest_bt).setOnClickListener{
Navigation.findNavController(it)
.navigate(R.id.homeGraph, null, NavOptions.Builder()
.setPopUpTo(R.id.startupGraph, false)
.build())
}
}
FlowStepOneFragment.
view.findViewById<View>(R.id.next_button).setOnClickListener {
Navigation.findNavController(it)
.navigate(R.id.flow_step_two, null, NavOptions.Builder()
.setPopUpTo(R.id.flow_step_one, true)
.build())
}
}
}
Causes the following error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.codelabs.navigation, PID: 12579
java.lang.IllegalArgumentException: Navigator androidx.navigation.fragment.FragmentNavigator@d70ec6f reported navigation to unknown destination id com.example.android.codelabs.navigation:id/flow_step_two
Description
Version used:1.0.0-alpha07
Devices/Android versions reproduced on: Emulator API 28, Xiaomi MI A1 8.1 (Android One)
If this is a bug in the library, we would appreciate if you could attach:
- Sample project to trigger the issue. - ATTACHED
Clicking on a Notification with PendingIntent created by NavDeepLinkBuilder uses the arguments of the last Notification created. For example: If you created notifications with fragment arguments 1, 2 and 3, then no matter which notification you click on, the fragment is started with argument 3.