Android Parcelable.


Parcelable is an interface that allows its implementers to be writable to and restorable from a parcel.

A parcel is a class that acts as a holder for both data and IBinder objects that can be sent through an IBinder.

Parcelable has existed in the android framework all the way since API level 1.

Pareclable Interface Definition

Parcelable is an interface hence it's implemented and not directly instantiated.

public interface Parcelable{}

Parcelable resides in the android.os package:

package android.os

Function

  1. Allows for the placement of arbitrary objects into a Parcel.

Usage

As an interfacce Parcelable has to be implemented by classes.

Those classes must have a non-null static field called CREATOR. This field is of data type that implements Parcelable.Creator.

Here's an example:

 public class MyParcelable implements Parcelable {
     private int mData;

     public int describeContents() {
         return 0;
     }

     public void writeToParcel(Parcel out, int flags) {
         out.writeInt(mData);
     }

     public static final Parcelable.Creator<MyParcelable> CREATOR
             = new Parcelable.Creator<MyParcelable>() {
         public MyParcelable createFromParcel(Parcel in) {
             return new MyParcelable(in);
         }

         public MyParcelable[] newArray(int size) {
             return new MyParcelable;
         }
     };

     private MyParcelable(Parcel in) {
         mData = in.readInt();
     }
 }

How do You Feel after reading this?

According to scientists, we humans have 8 primary innate emotions: joy, acceptance, fear, surprise, sadness, disgust, anger, and anticipation. Feel free to tell us how you feel about this article using these emotes or via the comment section. This feedback helps us gauge our progress.

Help me Grow.

I set myself some growth ambitions I desire to achieve by this year's end regarding this website and my youtube channel. Am halfway. Help me reach them by:




Recommendations


What do You Think


Previous Post Next Post