Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Safe Args: use list of parcelables

Tags:

I am using the Safe Args plugin with the new Navigation components for my Android project. Now I have an argument that is an array list of parcelables, is there a way to use this with the Safe Args Plugin?

Something like app:argType=ParcelableArray. This should be possible since there are bundle methods like putParcelableArrayList().

like image 848
botflot Avatar asked Nov 28 '18 13: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.

Is there any dependency that needs to get added before using SafeArgs?

Navigation SafeArgs Navigation Safe Args has upgraded the Android Gradle Plugin dependency to rely on 7.0. 4 , dropping compatibility for AGP versions before 7.0 . Added support for the namespace build. gradle attribute to be used instead of applicationId.


1 Answers

Yes, since version 1.0.0-alpha08 you can now pass arrays of parcelable objects like this:

<argument   android:name="users"   app:argType="com.navigation.test.User[]"/> 

For passing arrays of primitive types use for e.g. app:argType="integer[]"

like image 89
LaVepe Avatar answered Sep 21 '22 16:09

LaVepe