android-Parcelable

Parcelable

public interface Parcelable 

android.os.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.

接口类的实例可以写入和恢复从一个包裹。实现Parcelable接口的类必须有一个非空静态字段叫CREATOR 的实现Parcelable.Creator接口的类型。

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();
     }
 }

Summary


Nested classes

interface Parcelable.ClassLoaderCreator<T>

Specialization of Parcelable.Creator that allows you to receive the ClassLoader the object is being created in. 

序列化Parcelable.Creator让你来接收类加载器中创建的对象。

interface Parcelable.Creator<T>

Interface that must be implemented and provided as a public CREATOR field that generates instances of your Parcelable class from a Parcel. 

必须实现的接口,并提供了作为一个公共的 CREATOR  Parcelable类的字段生成实例从一个包裹。

Constants

int CONTENTS_FILE_DESCRIPTOR

Descriptor bit used with describeContents(): indicates that the Parcelable object's flattened representation includes a file descriptor.

int PARCELABLE_WRITE_RETURN_VALUE

Flag for use with writeToParcel(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)".

Public methods

abstract int describeContents()
//内容描述接口,基本不用管

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.

abstract void writeToParcel(Parcel dest, int flags)

Flatten this object in to a Parcel.

这个对象在一个包裹。

Constants


CONTENTS_FILE_DESCRIPTOR

Added in  API level 1
int CONTENTS_FILE_DESCRIPTOR

Descriptor bit used with describeContents(): indicates that the Parcelable object's flattened representation includes a file descriptor.

See also:

Constant Value: 1 (0x00000001)

PARCELABLE_WRITE_RETURN_VALUE

Added in  API level 1
int PARCELABLE_WRITE_RETURN_VALUE

Flag for use with writeToParcel(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.

Constant Value: 1 (0x00000001)

Public methods


describeContents

Added in  API level 1
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
int a bitmask indicating the set of special object types marshaled by this Parcelable object instance.

writeToParcel

Added in  API level 1
void writeToParcel (Parcel dest, 
                int flags)

Flatten this object in to a Parcel.

Parameters
dest Parcel: The Parcel in which the object should be written.
flags int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值