Use parcelable with safe args in navigation components
Asked Answered
E

1

7

I want to use Parcelable with the Navigation Components and Safe Args in version 1.0.0-alpha07. Although since alpha 03 Parcelable should be supported by Safe Args, but I'm not able to use them. The only way to use it is with app:argType="android.os.Parcelable" which doesn't seem like the right way for me.

If I use only app:argType="Parcelable" there is no import generated in the generated classes. Therefore what's the right way to use Parcelable with Safe Args?

Easterling answered 23/11, 2018 at 15:37 Comment(0)
T
8

You need Android Studio 3.3 and above. Create parcelable object, then go to navigation editor, select destination for which you want to create argument. Then click on add icon on arguments section on the right:

enter image description here

Then select custom parcelable from drop down list:

enter image description here

And choose your parcelable class:

enter image description here

Teevens answered 29/11, 2018 at 13:41 Comment(5)
Which version are you using? I only have infered, integer, string and reference.Easterling
@DevSte 1.0.0-alpha07Teevens
@DevSte i think you need Android Studio 3.3Teevens
I use 1.0.0-alpha07, but Android Studio 3.2.1. How does it look in the xml file?Easterling
<argument android:name="users" app:argType="il.co.globalbit.www.navigation5.Users"/>Teevens

© 2022 - 2024 — McMap. All rights reserved.