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

Giulio

03/18/2018, 8:19 PM
Quick beginner's question. If I have a long list of objects and I want to start another intent (to save them to a file for example), how should I pass the list to the intent?
a

anton.golovin

03/18/2018, 8:24 PM
Your objects should implement Parcelable (check
Parcelize
in Kotlin). Or Serializable.
a

Ash

03/18/2018, 8:26 PM
yea parcelable is better option than serialization
g

Giulio

03/18/2018, 8:26 PM
Yes, thank you! Sorry for the stupid question but why shouldn't I simply make the list static?
I mean without any putExtra
r

rkeazor

03/18/2018, 8:57 PM
lol Giulio, that would just be the beginning to alot of messy untestable code
always try to follow best practices when you can, it pays off in the long run
a

agrosner

03/18/2018, 9:35 PM
I would avoid sending list of objects in an intent unless you know it will be small. You will run into the parcel limit size
Why do you need to pass them through an intent to just write to file?
g

Giulio

03/18/2018, 9:48 PM
Hi indeed I am making the list static. Let's say I want a new intent where I gather other data from the user that is needed to complete the file structure before saving it...
a

agrosner

03/18/2018, 11:38 PM
Def avoid passing a list of objects through intents...you will run into crashes that you won't be able to easily diagnose due to parcel exception
g

Giulio

03/19/2018, 12:24 AM
Already done a static list without issues. Avoided the extraPut for all these items. I agree with you. Do you want to know practical reasons for crashes? Intents not correctly declared in the manifest and similar weird stuff of android apis... ids not found in the getView of an array list adapter... items overflowing a linear layout... etc, really fixing crashes has become my strength And no, not even one crash due to my static list 😉
2 Views