Parcel , Parcelable, Bundle,

来源:互联网 发布:python中文文本相似度 编辑:程序博客网 时间:2024/05/02 06:46

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 theParcelable.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

0 0
原创粉丝点击