Fixed
Status Update
Comments
cl...@google.com <cl...@google.com>
ap...@google.com <ap...@google.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
cl...@google.com <cl...@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
na...@google.com <na...@google.com> #4
Fixed internally and available in navigation 2.8.5
.
Description
Component used: Navigation
Version used: 2.8.5
The attempts to fill in the
NavDestination.fillInLabel
methodlabel
of theNavDestination
with arguments. However, it does this by (in every case butNavType.ReferenceType
) by just callingargs[argName].toString()
- e.g., just directly callingtoString()
on the object in theSavedState
bundle.While this approach works for simple types, a custom
NavType
might not store their class directly in the Bundle - for example, if using the@Serializable
support, it would be stored as aBundle
, which means thetoString()
is unlikely to actually be what is needed.Instead,
fillInLabel
should take into account theNavType
and use itsget
method to give theNavType
control over exactly the object that is synthesized from the arguments. That way, developers could implement a customtoString()
implementation on their object to control how it is displayed in the label.