Fixed
Status Update
Comments
ia...@gmail.com <ia...@gmail.com> #2
This is an issue when using inferred types (i.e., not specifying an app:argType) and android:defaultValue="@null".
You can work around this issue by specifying app:argType="string" on your <argument>:
<action
android:id="@+id/createModel"
app:destination="@id/editFragment" >
<argument
android:name="modelId"
app:argType="string"
android:defaultValue="@null" />
</action>
As an alternative, you can instead add your android:defaultValue="@null" to your android:id="@+id/editFragment"'s argument and leave out the <argument> entirely on your action, but that does have a slightly different semantic meaning when it comes to EditFragmentArgs' parsing.
You can work around this issue by specifying app:argType="string" on your <argument>:
<action
android:id="@+id/createModel"
app:destination="@id/editFragment" >
<argument
android:name="modelId"
app:argType="string"
android:defaultValue="@null" />
</action>
As an alternative, you can instead add your android:defaultValue="@null" to your android:id="@+id/editFragment"'s argument and leave out the <argument> entirely on your action, but that does have a slightly different semantic meaning when it comes to EditFragmentArgs' parsing.
il...@google.com <il...@google.com> #3
Project: platform/frameworks/support
Branch: androidx-master-dev
commit f3dff7e6da2365602626d0d24b68c340db4c9c7c
Author: Daniel Santiago Rivera <danysantiago@google.com>
Date: Mon Apr 01 22:36:01 2019
Use NullValue when inferring String with "@null" as default value.
Bug: 129629192
Test: ./gradlew navigation:navigation-safe-args-gradle-plugin:test
Change-Id: Ide6ecceac6de75f207b1ffaa080c5f5b7f5c2b66
M navigation/safe-args-generator/src/main/kotlin/androidx/navigation/safe/args/generator/NavParser.kt
M navigation/safe-args-generator/src/tests/kotlin/androidx/navigation/safe/args/generator/NavParserTest.kt
M navigation/safe-args-generator/src/tests/test-data/naive_test.xml
https://android-review.googlesource.com/937354
https://goto.google.com/android-sha1/f3dff7e6da2365602626d0d24b68c340db4c9c7c
Branch: androidx-master-dev
commit f3dff7e6da2365602626d0d24b68c340db4c9c7c
Author: Daniel Santiago Rivera <danysantiago@google.com>
Date: Mon Apr 01 22:36:01 2019
Use NullValue when inferring String with "@null" as default value.
Bug: 129629192
Test: ./gradlew navigation:navigation-safe-args-gradle-plugin:test
Change-Id: Ide6ecceac6de75f207b1ffaa080c5f5b7f5c2b66
M navigation/safe-args-generator/src/main/kotlin/androidx/navigation/safe/args/generator/NavParser.kt
M navigation/safe-args-generator/src/tests/kotlin/androidx/navigation/safe/args/generator/NavParserTest.kt
M navigation/safe-args-generator/src/tests/test-data/naive_test.xml
ma...@gmail.com <ma...@gmail.com> #4
Regarding the workarounds for #2, the first one requires app:nullable="true" both on the destination and the action. IOW, I wind up with an action like:
<action
android:id="@+id/createModel"
app:destination="@id/editFragment">
<argument
android:name="modelId"
android:defaultValue="@null"
app:argType="string"
app:nullable="true" />
</action>
That's fine -- I only mention it because the code snippet in #2 did not have it.
The second approach (put the default value on the destination's argument) also works, and in my case it's a better solution anyway, so I'll go with that.
Many thanks!
<action
android:id="@+id/createModel"
app:destination="@id/editFragment">
<argument
android:name="modelId"
android:defaultValue="@null"
app:argType="string"
app:nullable="true" />
</action>
That's fine -- I only mention it because the code snippet in #2 did not have it.
The second approach (put the default value on the destination's argument) also works, and in my case it's a better solution anyway, so I'll go with that.
Many thanks!
il...@google.com <il...@google.com>
ap...@google.com <ap...@google.com> #5
You're correct - if you're using android:defaultValue="@null", you'd need app:nullable="true".
This has been fixed internally and will be available in Navigation 2.1.0-alpha03 (it missed the alpha02 cutoff).
This has been fixed internally and will be available in Navigation 2.1.0-alpha03 (it missed the alpha02 cutoff).
il...@google.com <il...@google.com> #6
Passing arguments to the start destination can now be done via
NavHostFragment.create(R.navigation.graph, args)
or
navController.setGraph(R.navigation.graph, args)
or
navController.setGraph(navGraph, args)
This will be available in alpha07
NavHostFragment.create(R.navigation.graph, args)
or
navController.setGraph(R.navigation.graph, args)
or
navController.setGraph(navGraph, args)
This will be available in alpha07
[Deleted User] <[Deleted User]> #7
Component used: Navigation graph
Version used: 1.0.0-rc02
Devices/Android versions reproduced on: Device running Android P, compiled in SDK 28
Marked as fixed.
1.declare NavHostFragment with id
2. Inflate the container
3. declare navGraph with id
4.Extract from Intent
5. val navArgument= NavArgument.Builder().setDefaultValue("Required Bundle").build()
6.Add argument with graph
val navHostFragment = container as NavHostFragment
val inflater = navHostFragment.navController.navInflater
val graph = inflater.inflate(R.navigation.wash_request)
var place : String = intent?.getStringExtra("place") as String
var latlong : String = intent?.getStringExtra("latlong") as String
var selectCar = CarWashDetail(place,latlong)
val navArgument= NavArgument.Builder().setDefaultValue(selectCar).build()
graph.addArgument("CarWashDetails",navArgument)
navHostFragment.navController.graph = graph
Version used: 1.0.0-rc02
Devices/Android versions reproduced on: Device running Android P, compiled in SDK 28
Marked as fixed.
1.declare NavHostFragment with id
2. Inflate the container
3. declare navGraph with id
4.Extract from Intent
5. val navArgument= NavArgument.Builder().setDefaultValue("Required Bundle").build()
6.Add argument with graph
val navHostFragment = container as NavHostFragment
val inflater = navHostFragment.navController.navInflater
val graph = inflater.inflate(R.navigation.wash_request)
var place : String = intent?.getStringExtra("place") as String
var latlong : String = intent?.getStringExtra("latlong") as String
var selectCar = CarWashDetail(place,latlong)
val navArgument= NavArgument.Builder().setDefaultValue(selectCar).build()
graph.addArgument("CarWashDetails",navArgument)
navHostFragment.navController.graph = graph
Description
Version used: 1.0.0-alpha01
Devices/Android versions reproduced on: Device running Android P, compiled in SDK 27
If this is a bug in the library, we would appreciate if you could attach:
- Sample project to trigger the issue.
- A screenrecord or screenshots showing the issue (if UI related).
In order to instantiate the view of my first fragment, some data needs to be passed from the current Activity to the primary fragment. Currently, I don't see a clear way to do this. In the same way one can navigate from fragment to fragment while passing arguments via the NavController's navigate method, it would be helpful if there was some method to pass a bundle to the first nav fragment and update the graph associated with the NavHostFragment before inflating the view.
Please do let me know if there is some way to do this that I'm missing. Currently I'm setting up a dummy fragment to start with that will manage passing the data to the intended first fragment.