The new navigation component is great! however I would like to send "Long" variables between my fragments.
writing this in the navigation graph file works:
<argument
android:name="discussionId"
app:type="string" />
writing this won't compile:
<argument
android:name="discussionId"
app:type="long" />
Currently, it seems I'm forced to parse them to and from string formats. It works fine, but it seems bizarre to me that I can't use primitive types such as long or byte or short for such a fundamental architecture. Am I missing something? Is this kind of feature set to be developed in the future?
SafeArgs is a gradle plugin that allows you to Pass data to destination UI components. It generates simple object and builder classes for type-safe navigation and access to any associated arguments. Safe Args is strongly recommended for navigating and passing data because it ensures type-safety.
In the Navigation editor, click on the destination that receives the argument. In the Attributes panel, click Add (+). In the Add Argument Link window that appears, enter the argument name, argument type, whether the argument is nullable, and a default value, if needed. Click Add.
Navigation refers to the interactions that allow users to navigate across, into, and back out from the different pieces of content within your app. Android Jetpack's Navigation component helps you implement navigation, from simple button clicks to more complex patterns, such as app bars and the navigation drawer.
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[]"
/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With