Is it possible to send arguments other than string or integer in android's new navigation component
Since version 1.0.0-alpha08 you can use a lot of different types, i have found a list here
"integer" -> IntType
"integer[]" -> IntArrayType
"long" -> LongType
"long[]" -> LongArrayType
"float" -> FloatType
"float[]" -> FloatArrayType
"boolean" -> BoolType
"boolean[]" -> BoolArrayType
"reference" -> ReferenceType
"reference[]" -> ReferenceArrayType
"string" -> StringType
"string[]" -> StringArrayType
null -> StringType
and for the used in navigation graph (for exemple: list of string)
<argument
android:name="photo_url"
app:argType="string[]"
/>
At the moment you can't use safe args with types apart from integer, string, inferred and reference. An issue has been opened asking for other types.
But you pass a bundle programmatically when using the navigate() method to navigate to a destination:
var bundle = bundleOf("key" to amount)
view.findNavController().navigate(R.id.action_id, bundle)
And you can use the usual getArguments
to retrieve the data in the destination fragment:
val value = arguments.getString("key")
Use primitive wrappers! What's wrong with it?
<argument
android:name="discussionId"
app:argType="java.lang.Long" />
// java.lang.Double, java.lang.Float, etc...
Works like a charm with kotlin and even with safe args because all primitive wrappers are implementing Serializable