The following is the first few sections of a chapter from The Busy Coder's Guide to Android Development, plus headings for the remaining major sections, to give you an idea about the content of the chapter.

Writing and Using Parcelables

Parcelable is a marker interface, reminiscent of Serializable, that shows up in many places in the Android SDK. Parcelable objects can be put into Intent extras or Bundle objects, for example. Making your own custom classes implement Parcelable greatly increases their flexibility.

At the same time, Parcelable is something that can be overused. In most Android apps, few if any custom classes really need to have Parcelable capabilities.

In this chapter, we will review how to modify classes to implement Parcelable and what the limitations are on using Parcelable.


Understanding this chapter requires that you have read the core chapters of this book.

The Role of Parcelable

A Parcelable object is one that can be placed into a Parcel. A Parcel is the primary vehicle for passing data between processes in Android’s inter-process communication (IPC) framework.

IPC abounds in Android, even in places where you may not expect it. Every time you call startActivity(), for example, IPC occurs, even if the activity that calls startActivity() and the activity to be started are in the same process. A core OS process is the one that is responsible for identifying the activity to be started and routing control to it, so startActivity() performs IPC from the original activity’s process to a core OS process. The core OS process then eventually performs IPC to the target process for the activity to be started.

If you see an Intent or a Bundle in the Android SDK, odds are that those objects are involved in IPC. That is not always the case — LocalBroadcastManager, for example, uses Intent objects purely in-process — but it is a reasonable rule of thumb. Hence, there is keen interest in being able to implement Parcelable on specific classes, either to pass to other components via Intent extras, or to become part of the saved instance state Bundle.

Parcelable objects are also important for use with remote services via the binding pattern.

Writing a Parcelable

The preview of this section is en route to Mars.

The Limitations of Parcelable

The preview of this section left for Hollywood to appear in a reality TV show.

Beware the PendingIntent

The preview of this section is presently indisposed.