Is it possible to send arguments other than string or integer in android's new navigation component

MichaelThePotato picture MichaelThePotato · Jun 19, 2018 · Viewed 11.7k times · Source

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?

Answer

Guillaume picture Guillaume · Dec 26, 2018

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[]"
/>