首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

android 序列化 Serializable 与Parcelable 的差异

2012-07-18 
android 序列化 Serializable 与Parcelable 的区别Serializable is a standard Java interface. You simpl

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 ?填充数据的地方

热点排行