Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use parcelable with safe args in navigation components

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?

like image 257
botflot Avatar asked Nov 23 '18 15:11

botflot


People also ask

Why do we use safe args instead of bundle approach?

Safe Args is strongly recommended for navigating and passing data, because it ensures type-safety. In some cases, for example if you are not using Gradle, you can't use the Safe Args plugin. In these cases, you can use Bundles to directly pass data. You must also apply one of two available plugins.

What does the safe args gradle plugin do select all that apply?

What does the Safe Args Gradle plugin do? Select all that apply. Choose as many answers as you see fit. Generates simple object and builder classes for type-safe access to arguments specified for destinations and actions.


1 Answers

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

like image 94
Alex Avatar answered Oct 05 '22 23:10

Alex