Fixed
Status Update
Comments
il...@google.com <il...@google.com> #2
There is indeed an issue in how we maintain the back stack that is the root cause of this issue and we'll fix that.
Note that this issue occurs in your code because you have the onboarding Fragment as the start destination of your graph, something that is specifically not supported:https://developer.android.com/guide/navigation/navigation-principles#fixed_start_destination - this is also what causes all of your destinations to remain on the back stack (i.e., Home, List, Home all exist on the back stack, rather than being cleared out) as NavigationUI assumes you are doing the correct thing regarding your start destination.
As per the conditional navigation documentation (https://developer.android.com/guide/navigation/navigation-conditional#first-time_user_experience ), you should be launching your onboarding flow from your actual start destination and not using it as a start destination itself.
Note that this issue occurs in your code because you have the onboarding Fragment as the start destination of your graph, something that is specifically not supported:
As per the conditional navigation documentation (
be...@gmail.com <be...@gmail.com> #3
Thank you for explaining. I applied your recommendations and it works. I attached the update app for others who might be interested.
jb...@google.com <jb...@google.com>
ap...@google.com <ap...@google.com> #4
Project: platform/frameworks/support
Branch: androidx-master-dev
commit 1a9c91a3e6c4099d438db6231448293ac82f65b2
Author: jbwoods <jbwoods@google.com>
Date: Tue May 07 10:18:18 2019
Ensure destinations are linked properly on nav back stack
Currently when we navigate to a destination, if its ancestors are
already on the nav back stack, we do not re-add them. This can cause
an issue when we save and restore where destinations on the back stack
are not reachable, causing an unknown destination IllegalStateException.
When navigating to a destination, we should add the ancestors needed to
get to that destination from the current one to the back stack. This
ensures that on restore we have the proper path to access all
destinations and rebuild the entire navigation graph.
Test: test app, new test, reran nav test
BUG: 131733658
Change-Id: I6f07fb3ba2ccf2c691b66df304a4f3c160313d82
M navigation/runtime/src/androidTest/java/androidx/navigation/NavControllerTest.kt
M navigation/runtime/src/main/java/androidx/navigation/NavController.java
https://android-review.googlesource.com/956845
https://goto.google.com/android-sha1/1a9c91a3e6c4099d438db6231448293ac82f65b2
Branch: androidx-master-dev
commit 1a9c91a3e6c4099d438db6231448293ac82f65b2
Author: jbwoods <jbwoods@google.com>
Date: Tue May 07 10:18:18 2019
Ensure destinations are linked properly on nav back stack
Currently when we navigate to a destination, if its ancestors are
already on the nav back stack, we do not re-add them. This can cause
an issue when we save and restore where destinations on the back stack
are not reachable, causing an unknown destination IllegalStateException.
When navigating to a destination, we should add the ancestors needed to
get to that destination from the current one to the back stack. This
ensures that on restore we have the proper path to access all
destinations and rebuild the entire navigation graph.
Test: test app, new test, reran nav test
BUG: 131733658
Change-Id: I6f07fb3ba2ccf2c691b66df304a4f3c160313d82
M navigation/runtime/src/androidTest/java/androidx/navigation/NavControllerTest.kt
M navigation/runtime/src/main/java/androidx/navigation/NavController.java
il...@google.com <il...@google.com> #5
We've fixed the underlying issue internally and this will be available in Navigation 2.1.0-alpha04
fe...@gmail.com <fe...@gmail.com> #6
I have the same error on screen rotation:
Caused by: java.lang.IllegalStateException: unknown destination during restore: com.example.fcruzgo.servicioscasabolsa2.login:id/login_graph
In my case I add the graph from a dinamic module by reflection:
val navController: NavController = findNavController(R.id.nav_host_fragment)
val loginGraph = resources.getIdentifier("login_graph", "navigation", packageName + ".login")
val destinationGraph = navController.navInflater.inflate(loginGraph)
navController.graph.addDestination(destinationGraph)
then I use destinationGraph.id to navigate to the destination, in this case the login graph that containts the login fragment.
Caused by: java.lang.IllegalStateException: unknown destination during restore: com.example.fcruzgo.servicioscasabolsa2.login:id/login_graph
In my case I add the graph from a dinamic module by reflection:
val navController: NavController = findNavController(R.id.nav_host_fragment)
val loginGraph = resources.getIdentifier("login_graph", "navigation", packageName + ".login")
val destinationGraph = navController.navInflater.inflate(loginGraph)
navController.graph.addDestination(destinationGraph)
then I use destinationGraph.id to navigate to the destination, in this case the login graph that containts the login fragment.
fe...@gmail.com <fe...@gmail.com> #7
I have the same error on screen rotation:
Caused by: java.lang.IllegalStateException: unknown destination during restore: com.example.fcruzgo.servicioscasabolsa2.login:id/login_graph
In my case I add the graph from a dinamic module by reflection:
val navController: NavController = findNavController(R.id.nav_host_fragment)
val loginGraph = resources.getIdentifier("login_graph", "navigation", packageName + ".login")
val destinationGraph = navController.navInflater.inflate(loginGraph)
navController.graph.addDestination(destinationGraph)
then I use destinationGraph.id to navigate to the destination, in this case the login graph that containts the login fragment.
Component used: Navigation
Version used: 2.1.0-alpha05
Caused by: java.lang.IllegalStateException: unknown destination during restore: com.example.fcruzgo.servicioscasabolsa2.login:id/login_graph
In my case I add the graph from a dinamic module by reflection:
val navController: NavController = findNavController(R.id.nav_host_fragment)
val loginGraph = resources.getIdentifier("login_graph", "navigation", packageName + ".login")
val destinationGraph = navController.navInflater.inflate(loginGraph)
navController.graph.addDestination(destinationGraph)
then I use destinationGraph.id to navigate to the destination, in this case the login graph that containts the login fragment.
Component used: Navigation
Version used: 2.1.0-alpha05
th...@gmail.com <th...@gmail.com> #8
I still get this issue with navigation library 2.2.0 even though it says it was fixed in 2.1.0
il...@google.com <il...@google.com> #9
Re #6, #7 - please file a new bug with a sample project that reproduces your issue.
vi...@gmail.com <vi...@gmail.com> #10
Any updates on this bug? having this issue even after updating to 2.2.0
il...@google.com <il...@google.com> #11
Re #10 - We have not received any reproducible sample projects with 2.2.0 that exhibit this issue. Please file a new bug with a sample project if you have one and we can take a look.
Description
Version used: 1.0.0
Devices/Android versions reproduced on: Pixel 2 API 28
Upon screen rotation (or activity recreation), the app crashes after following a few simple steps.
Steps to reproduce (see screen recording) :
1. Click on List to navigate to ListFragment
2. Click on Main to navigate to MainFragment
3. Rotate screen
Navigation features :
- NavigationUI
- Conditional navigation
- Nested graphs
- Global action with popUpTo and popUpToInclusive