Parcel , Parcelable, Bundle,


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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值