Parcel: 存放可parcel的容器,提供接口读写
1。 基本的类型和基本类型的数组
2。Parcelable和Parcelable的数组
3。Bundle (Bundle本身实现了Parcelable接口) (Bundle中value必须为可写入到Parcel中)
4。Active Object:For these objects the actual contents of the object is not written, rather a special token referencing the object is written.
5。Untyped Contains
Parcelable:
能把自己写到Parcel的接口。提供一个field called CREATOR
, which is an object implementing the Parcelable.Creator
interface.
实现这个接口就实现了从Parcel读和写到Parcel的函数。
describeContents() ?? 不明白
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(); } }
Bundle: A mapping from String values to various Parcelable types. 并不能放任意的Qobject