Quick beginner's question. If I have a long list o...
# android
g
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
Your objects should implement Parcelable (check
Parcelize
in Kotlin). Or Serializable.
a
yea parcelable is better option than serialization
g
Yes, thank you! Sorry for the stupid question but why shouldn't I simply make the list static?
I mean without any putExtra
r
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
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
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
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
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 😉