读书人

android 序列化 Serializable 与Parce

发布时间: 2012-07-18 12:05:41 作者: rapoo

android 序列化 Serializable 与Parcelable 的区别

Serializable is a standard Java interface. You simply mark a class Serializable by implenting the interface, and Java will automatically serialize it in certain situations.

Parcelable is an Android specific interface where you implement the serialization yourself. It was created to be far more efficient that Serializable, and to get around some problems with the default Java serialization scheme.

I believe that Binder and AIDL work with Parcelable objects.

However, you can use Serializable objects in Intents.

?

Parcelable ?需要实现的2个接口

?

?

public int describeContents() {

// TODO Auto-generated method stub

return 0;

}

public void writeToParcel(Parcel dest, int flags) {

// TODO Auto-generated method stub

dest.writeInt(id);

dest.writeString(data);

dest.writeString(displayName);

dest.writeInt(isSelected?1:0);

}


关键是writeToParcel ?填充数据的地方

读书人网 >Android

热点推荐