Parcels and Bundles

From Android Wiki

(Difference between revisions)
Jump to: navigation, searcha
m (Reverted edits by Ipodsoft (talk) to last revision by Loonix)
 
Line 8: Line 8:
[[Category:Programming]]
[[Category:Programming]]
-
 
-
 
-
'''Source(s):'''  [http://www.downloadranking.com  Android solutions]
 

Latest revision as of 08:46, 31 January 2013

Parcels and Bundles are the two main serialization mechanisms used for interprocess communication in Android. The difference between them is that, in a Parcel, items must be read back in the same sequence they were written, whereas in a Bundle, items are identified by a key string, and so can be read back in any order by specifying the corresponding keys. Parcels are the primary mechanism, but one of the things a Parcel can contain is a Bundle.

Parcelable is an interface that your objects can implement in order to save their state to, and restore it from, a Parcel. The important components of this are

  • A writeToParcel method which can be called to save your object state to a specified Parcel, and
  • A CREATOR static field, which contains a custom instance of Parcelable.Creator, which knows how to recreate your Parcelable object from a specified Parcel, as previously written by your writeToParcel method.

Even though this interface specifically mentions Parcels, Bundles can also contain Parcelable objects.

Personal tools