Android TIP: Quick generating Parcelable implement with a plugin in Android Studio

     Along with Serializable, Parcelable is a data type that we usually pass through Intent or Bundle when switching to another Activity or Fragment. This is an interface for classes whose instances can be written to and restored from a Parcel. Parcelable process is much faster than Serializable (a standard interface in JDK). One of the reasons for this is that we are being explicit about the serialization process instead of using reflection to infer it. It also stands to reason that the code has been heavily optimized for this purpose.
    Classes implementing the Parcelable interface must also have a non-null static field called CREATOR of a type that implements the Parcelable.Creator interface. More over, there are some methods you must override:
  • describeContents(): describe the kinds of special objects contained in this Parcelable's marshalled representation. Return a bitmask indicating the set of special object types marshalled by the Parcelable.
  • writeToParcel(): flatten this object in to a Parcel.
  • A constructor with Parcel as the parameter: read all class variables from Parcel.
    As you can see, not simple like implement Serializable, by making a class which implements Parcelable we must write a lot of boring/similar codes (especially your class has so many private variables). So, as a lazy developer like me, you would think to use a generating tool. In this tip, I will present a powerful plugin on IntelliJ/Android Studio to make this work more comfortable and quickly.

Installing the plugin

    Step 1: Go to the plugin release page on Github and download the lastest jar file.
    Step 2: In Android Studio, select menu File -> Settings... (on Windows) or File -> Preferences... (on MacOS), select Plugin entry on the left-side pane. You will have this dialog:
    Step 3: Click at "Install plugin from disk" and select the download jar file:
     Step 4: Click "OK", the dialog will be closed and the plugin has installed. This dialog will appear and click "Restart" to restart Android Studio:

Usages in your class

    Just press ALT + Insert (or your equivalent keybinding for code generation) in your editor and select Parcelable. It allows you to select the fields to be parceled:
    And you will have this result:
package info.devexchanges.parcelableplugin;

import android.os.Parcel;
import android.os.Parcelable;

public class Customer implements Parcelable {

    private String name;
    private int id;

    public Customer(String name, int id) { = name; = id;
    public int describeContents() {
        return 0;

    public void writeToParcel(Parcel dest, int flags) {

    protected Customer(Parcel in) { = in.readString(); = in.readInt();

    public static final Creator CREATOR = new Creator() {
        public Customer createFromParcel(Parcel source) {
            return new Customer(source);

        public Customer[] newArray(int size) {
            return new Customer[size];
    Now, your work has been done without typing lengthy codes! For more details, please go to the plugin page on Github and read it's documentation! Moreover, check these reference links to understanding Parcelable in Android:


Previous post
« Prev Post
Next post
Next Post »