Question

I see parcel and serializable being used kind of interchangeably, or at least un-intuitively in the same context. Can you clarify some things for me?

  1. are parcel's persistent storage (on the disk) or stored in memory only

  2. do I need serializable to store parcel data to disk

thank you for the insight, and no, the android dev manual does not make this obvious to me

Was it helpful?

Solution

My answers:

  1. Parcels are for flattening objects so they can be stored somewhere other than the JVM's running memory.

  2. You do not need to mix serializable with parcels to store data to disk. One or the other alone is enough to store objects to disk.


Serializable and Parcelable are both ways to flatten your Java objects.

These flattened objects can be passed between processes via various transmission formats -- disk files included.

Serializable comes from core Java and is easy to use.

Parcelable comes from Android and is a little more complex.

This answer includes more details:

https://stackoverflow.com/a/5551155/523135

This blog post has sample code Parcelable:

http://blog.cluepusher.dk/2009/10/28/writing-parcelable-classes-for-android/

This blog post has sample Serializable code:

http://www.javapractices.com/topic/TopicAction.do?Id=45

OTHER TIPS

Read Parcel documentation. Parcel should not be placed in persistent storage.

Excerpt:

"...Parcel is not a general-purpose serialization mechanism. This class (and the corresponding Parcelable API for placing arbitrary objects into a Parcel) is designed as a high-performance IPC transport... "

"... it is not appropriate to place any Parcel data in to persistent storage: changes in the underlying implementation of any of the data in the Parcel can render older data unreadable."

http://developer.android.com/reference/android/os/Parcel.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top