Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.