Fixed
Status Update
Comments
cl...@google.com <cl...@google.com>
ap...@google.com <ap...@google.com> #2
Project: platform/frameworks/support
Branch: androidx-main
Author: Clara Fok <
Link:
Fix ActivityNavigator not encoding with NavType
Expand for full commit details
Fix ActivityNavigator not encoding with NavType
When navigating with dynamic arugments, ActivityNavigator should first try to encode the argument value with the associated NavType. If NavType is not present (XML file has dataPattern but not arguments added) then we should fallback to existing behavior of just encoding the arg value with toString().
Test: ./gradlew navigation:navigation-runtime:cC
Bug: 383616432
Relnote: "When navigating to activity with dataPattern, ActivityNavigator will now try to encode the arg value with the argument's NavType."
Change-Id: I163763c46090ae9b4c8ee75d52142986e507c0c3
Files:
- M
navigation/navigation-runtime/src/androidTest/java/androidx/navigation/ActivityNavigatorTest.kt
- M
navigation/navigation-runtime/src/main/java/androidx/navigation/ActivityNavigator.kt
Hash: ad1ddb7df46854191c753e309e72216fae9309de
Date: Mon Jan 06 15:51:40 2025
cl...@google.com <cl...@google.com> #3
Fixed internally and available in navigation 2.9.0-alpha05
na...@google.com <na...@google.com> #4
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.navigation:navigation-runtime:2.9.0-alpha05
androidx.navigation:navigation-runtime:2.8.6
zy...@gmail.com <zy...@gmail.com> #5
So now I have updated to the latest version of v2.8.7, resulting in some null exceptions. I used {text} in the label field, and then passed it in the bundle parameter of the navigate method, which was used normally in v2.8.5
java.lang.NullPointerException (Ask Gemini)
at androidx.navigation.NavDestination.fillInLabel(NavDestination.android.kt:670)
Now I have found a solution, that is, adding argument to navigation.
<fragment
android:id="id"
android:name="name"
android:label="{title_text}">
<argument
android:name="title_text"
app:argType="string" />
</fragment>
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.