Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Android Lists and Adapters (2015) Using Parcelable Data Using a Creator and Reading a Parcel

Andrés Núñez Visbal
Andrés Núñez Visbal
3,652 Points

A less annoying way to pass arrays of objects?

Hi to everyone,

In some videos before I don't remember if it was a Teacher's note or an Extra credit there was documentation about 3rd party libraries to work better with JSON like Gson and Jackson. So my question is, Is it necessary to do all the Parcelable things or is it better to parce my Objects to Strings (using the libraries) and then parce the Strings back to Objects?

Maybe the Parcelable way uses less resources of the phone or am I missing something?

1 Answer

Jon Kussmann
PLUS
Jon Kussmann
Courses Plus Student 7,254 Points

A library like Gson makes it easier to convert JSON into an object model. If you still want to pass an array of objects around, the best way is to still implement the Parcelable interface.

Andrés Núñez Visbal
Andrés Núñez Visbal
3,652 Points

But you can also convert a object model into JSON by using Gson, and then pass this JSON by putExtra and then in the other activity receive the JSON and parcing it back to the object model.

Jon Kussmann
Jon Kussmann
Courses Plus Student 7,254 Points

Yes, I suppose you could.

It's a little more of a "hacky" way of doing it, but that looks like it would work.

From what I'm seeing you shouldn't notice a significant performance difference.