Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 515
MichaelThePotato Avatar asked Jun 19 '18 18:06

MichaelThePotato


People also ask

What is safe args in navigation android?

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.

How do you pass bundle in navigation component?

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.

What are navigation components in Android?

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.


1 Answers

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[]"
/>
like image 80
Guillaume Avatar answered Oct 04 '22 22:10

Guillaume