Fixed
Status Update
Comments
wi...@gmail.com <wi...@gmail.com> #2
A Null Pointer Exception in Nav Controller when switching the start destination typically happens due to one of the following reasons:
Incorrect Initialization: The NavController might not be properly initialized before trying to set a new start destination. Ensure that the NavController is correctly associated with the Nav Host Fragment or Fragment Container View. Navigation Graph Not Set: If the navigation graph is not set before switching the start destination, it can lead to a Null Pointer Exception. Make sure the navigation
jb...@google.com <jb...@google.com>
cl...@google.com <cl...@google.com>
ap...@google.com <ap...@google.com> #3
Project: platform/frameworks/support
Branch: androidx-main
Author: Clara Fok <
Link:
Fix NavDestination mismatch when adding NavBackStackEntry
Expand for full commit details
Fix NavDestination mismatch when adding NavBackStackEntry
When navigating to a nested NavDestination, we trace the target destination's hierarchy and add its parents to the backstack. Since a destination can have different parents (i.e. same destination exists within different graphs), we check its parent for referential equality and add it only if that specific parent hasn't been added yet.
Part of this process includes searching for a specific parent instance. However, parents can also be duplicated - a parent destination can also exist in several different graphs. The current bug is due to findDestination returning the wrong parent duplicate.
So findDestination is modified to take an optional matchingDestination parameter. When matchingDestination is present, findDestination will attempt to return a destination that is equal (==) and has the same parent (same nesting) as the matchingDestination.
Bug: 361560785
Test: ./gradlew navigation:navigation-runtime:cC
Relnote: "Fixed NavDestination NullPointerException when updating a Graph's startDestination"
Change-Id: I99421bf1e4aef9802873d9d78fbc6fafc15a21ba
Files:
- M
navigation/navigation-common/src/main/java/androidx/navigation/NavGraph.kt
- M
navigation/navigation-runtime/src/androidTest/java/androidx/navigation/NavControllerRouteTest.kt
- M
navigation/navigation-runtime/src/main/java/androidx/navigation/NavController.kt
Hash: 7341ef64fbf832915b8ee6c1ed4838b5981fd886
Date: Wed Nov 13 11:45:32 2024
cl...@google.com <cl...@google.com> #4
Fixed internally and available in navigation 2.8.5
.
pr...@google.com <pr...@google.com> #5
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.navigation:navigation-common:2.9.0-alpha04
androidx.navigation:navigation-runtime:2.9.0-alpha04
androidx.navigation:navigation-common:2.8.5
androidx.navigation:navigation-runtime:2.8.5
co...@gmail.com <co...@gmail.com> #6
Comment has been deleted.
Description
Version used: 2.7.7
Devices/Android versions reproduced on: Pixel 3, Pixel 7 Pro
We recently experienced an app crash when switching our NavHost's startDestination. After some investigation, it seems like this is triggered only after having previously navigated between two routes, where the second route is nested inside of a nav graph whose route has the same name as a sibling of the starting route (causing them to have the same ID).
Fortunately, this means the crash can be avoided by avoiding those duplicates, but it was a bit tricky to find the cause of the NullPointerException, and it would be nice if it failed more gracefully than a NullPointerException with the possibility of crashing the app entirely.
I have attached a sample app which reproduces this crash.