Package android.os

Interface Parcelable


  • public interface Parcelable
    Interface for classes whose instances can be written to and restored from a Parcel. Classes implementing the Parcelable interface must also have a non-null static field called CREATOR of a type that implements the Parcelable.Creator interface.

    A typical implementation of Parcelable is:

     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[size];
             }
         };
         
         private MyParcelable(Parcel in) {
             mData = in.readInt();
         }
     }
    • Field Detail

      • PARCELABLE_WRITE_RETURN_VALUE

        static final int PARCELABLE_WRITE_RETURN_VALUE
        Flag for use with writeToParcel(android.os.Parcel, int): the object being written is a return value, that is the result of a function such as "Parcelable someFunction()", "void someFunction(out Parcelable)", or "void someFunction(inout Parcelable)". Some implementations may want to release resources at this point.
        See Also:
        Constant Field Values
      • PARCELABLE_ELIDE_DUPLICATES

        static final int PARCELABLE_ELIDE_DUPLICATES
        Flag for use with writeToParcel(android.os.Parcel, int): a parent object will take care of managing duplicate state/data that is nominally replicated across its inner data members. This flag instructs the inner data types to omit that data during marshaling. Exact behavior may vary on a case by case basis.
        See Also:
        Constant Field Values
    • Method Detail

      • describeContents

        int describeContents()
        Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. For example, if the object will include a file descriptor in the output of writeToParcel(Parcel, int), the return value of this method must include the CONTENTS_FILE_DESCRIPTOR bit.
        Returns:
        a bitmask indicating the set of special object types marshaled by this Parcelable object instance.
      • writeToParcel

        void writeToParcel​(android.os.Parcel dest,
                           int flags)
        Flatten this object in to a Parcel.
        Parameters:
        dest - The Parcel in which the object should be written.
        flags - Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE.