Interface Parcelable

All Known Subinterfaces:
ParcelableSpan
All Known Implementing Classes:
AbsoluteSizeSpan, AlignmentSpan.Standard, BackgroundColorSpan, DataSet, Editor.EditOperation, ForegroundColorSpan, LeadingMarginSpan.Standard, LineBackgroundSpan.Standard, LocaleSpan, RelativeSizeSpan, StrikethroughSpan, StyleSpan, SubscriptSpan, SuperscriptSpan, TrailingMarginSpan.Standard, TypefaceSpan, UnderlineSpan, UndoOperation, URLSpan

public interface Parcelable
Parcelable is a serialization method alternative to standard Java serialization. Instances can be written to and restored from a Parcel, avoiding the heavy overhead of Externalizable.
Classes implementing the Parcelable interface must also have a non-null static field called CREATOR of a type that implements the Parcelable.Creator or Parcelable.ClassLoaderCreator interface.

A typical implementation of Parcelable is:


 public class MyParcelable implements Parcelable {

     public static final Parcelable.Creator<MyParcelable> CREATOR
             = MyParcelable::new;

     private final int mData;

     public MyParcelable(@NonNull Parcel src) {
         mData = src.readInt();
     }

     @Override
     public void writeToParcel(@NonNull Parcel dest, int flags) {
         dest.writeInt(mData);
     }
 }
Since:
3.7
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Specialization of Parcelable.Creator that allows you to receive the ClassLoader the object is being created in.
    static interface 
    Interface that must be implemented and provided as a public CREATOR field that creates instances of your Parcelable class from a Parcel.
    static @interface 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    writeToParcel(Parcel dest, int flags)
    The subclass implements the method to flatten its contents by calling the methods of Parcel for its primitive values.
  • Method Details

    • writeToParcel

      void writeToParcel(@NonNull Parcel dest, int flags)
      The subclass implements the method to flatten its contents by calling the methods of Parcel for its primitive values.
      Parameters:
      dest - the parcel to write the object's data to
      flags - the flags about how the object should be written