ixx
ixx

Reputation: 32269

Is parcelable worth to implement to pass data between activities?

I want to improve the performance of my app. One thing which comes to my mind is to replace all the serializable intent-bundle parameters with parcelable.

I found this thread: Benefit of using Parcelable instead of serializing object

There somebody states, from a book, that parcelable is only meant to be used for interprocess communication? That's probably not up to date, anymore, right? Because it is, technically at least, possible.

Then there's also the statement that parcelable is not reliable because the implementation varies accross devices, this would be of course a killing characteristic, since I want it to work always, all devices and apis, starting from API 7.

And I also read some advices about using Externalizable or implementing a custom protocol... but I don't understand, why Parcelable is not reliable, why Android developers do such buzz around something which will not work on all devices? Or is the comment not true?

Is it worth to implement Parcelable? Do I stick with Serializable? Or is a custom serialization / Externalizable the right approach?

Please don't tell me "just try", I don't have time for this, specially to check if Parcelable is reliable (and also not enough devices)... experience is asked...

Thanks.

P.S. Also don't say me "Serializable will be acceptable for most cases" I know that, it's indeed acceptable but I have time and would like to use it with Parcelable (or something else), if this improves the user experience.

Upvotes: 5

Views: 2562

Answers (2)

Michel-F. Portzert
Michel-F. Portzert

Reputation: 1785

There somebody states, from a book, that parcelable is only meant to be used for interprocess communication? That's probably not up to date, anymore, right? Because it is, technically at least, possible.

If Parcelable was not meant to be passed between activities, why does the putExtra (String name, Parcelable value) Intent method exists since API Level 1?

Then there's also the statement that parcelable is not reliable because the implementation varies accross devices, this would be of course a killing characteristic, since I want it to work always, all devices and apis, starting from API 7.

Let my quote the Parcel documentation:

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. As such, 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.

Here I can only read an advice about not storing a Parcel data into persistent storage. From my personal experience Parcelable was never an issue for passing data between activities. I heavily use it and support API 8 to current API.

Concerning performance and speed it's established that using Parcelable is better, as it is an Android specific high-performance IPC transport serialization mechanism. Though, in order to actually see an improvement, it should depends on how much you use it.

Upvotes: 4

David Wasser
David Wasser

Reputation: 95618

Parcelable works always, all the time, on all devices. If it didn't, nothing would work. Android internals rely very heavily on Parcelable.

Parcelable will be a bit more efficient than Serializable but I seriously doubt that it would have much impact on your "user experience" (unless, of course, you are using it all over the place and serializing very large and complicated objects).

If you think you are having performance issues, then I would spend my available time profiling the application and gathering empirical data about where it is spending its time. IMHO replacing Serializable with Parcelable is a relatively low-level implementation optimization that is likely to give you close to zero perceivable performance improvement.

Upvotes: 6

Related Questions