https://kotlinlang.org logo
#android
Title
# android
w

wilburt

06/18/2017, 11:35 PM
Is there plug-in to generate parcellables in Kotlin like in former java POJO classes?
s

scott

06/19/2017, 3:41 PM
wilburt: I would be careful about parcellables. If you need a plug-in there’s a good chance you are parceling way too much.
w

wilburt

06/19/2017, 3:49 PM
@scott I usually used them in POJO classes when it needs to be passed around via intents. Isn't that ok?
s

scott

06/19/2017, 3:51 PM
you definitely can. but I wouldn’t. There are restrictions on size, and can slow down main thread a ton. Better to just put the id of the object in the bundle like bundle.putInt(“somePojoId”,25) and then grab the object from the repository/interactor/etc.
then it’s simpler code, no crazy parcelable code, data will always be live and don’t need to copy anything, and faster initialization time of the new activity/fragment/etc.
w

wilburt

06/19/2017, 4:10 PM
Thanks. This makes more sense.
Ok let's say I got a json response and converted it into a list of POJOs. Now, I want to implement some kind list-detail fragments, if I pass the id of the pojo to the detail activity and send another request to get; is that too much overhead as compared to parcellables?
Please I am not saying you're wrong, I just needed a little clarification.
s

scott

06/19/2017, 5:16 PM
no problem. I don’t mind disagreement don’t worry. that data should NOT live in the activities anyway. that data lives outside the UI. and then you can do the request before and parcel the id or the query like bundle.putString(“moviesList”, “spielberg”)
data should live in some repository or datastore or something right. otherwise you lose the data when activity dies, config changes, etc.
and you can’t independantly test your data. and your data logic and persistance/caching is all in your activity which means it’s tightly coupled and you can’t reuse it.
w

wilburt

06/19/2017, 8:03 PM
It's more clearer now. Thanks.
s

scott

06/19/2017, 8:05 PM
👍