MarcinMoskala / ActivityStarter

Simple Android Library, that provides easy way to start the Activities with arguments.
http://marcinmoskala.com/ActivityStarter/
Apache License 2.0
431 stars 31 forks source link

var ArrayList of Parcelable problem #27

Open btwarog opened 6 years ago

btwarog commented 6 years ago

Library version 1.11-beta

There is an issue if you would try to pass an ArrayList with this library, CustomElement has annotation @Parcelize and extends Parcelable.

For single element it's correctly generating fill method in x*Starter class for example it would look like: activity.setCustomElement((CustomElement)savedInstanceState.getParcelable(CUSTOM_ELEMENT_KEY)); But for an ArrayList of this CustomElement it look like: activity.setCustomElements(savedInstanceState.getParcelableArrayList(CUSTOM_ELEMENTS_KEY)); And Android Studio marks it as error.

MarcinMoskala commented 6 years ago

savedInstanceState is a Bundle which has getParcelableArrayList method and this is preferred way to pass list of elements as an argument. It is even tested. Can you give some more specific example?

btwarog commented 6 years ago

I've downloaded your sample, tested it and it's not @Parcelize annotation problem. To see what I mean just add in StudentParcelableActivity.kt the following line.

@get:Arg var students: ArrayList<StudentParcelable> by argExtra()

Your library work correctly in Kotlin for: @get:Arg val students: ArrayList<StudentParcelable> by argExtra()

but it's not working for: @get:Arg var students: ArrayList<StudentParcelable> by argExtra()

It's the problem of var in case of ArrayList with elements that extends Parcelable.