由于Serializable效率过慢,为了在程序内不同组件及进程间(AIDL)高效的传输数据,Android推出了Parceable的设计,这些数据仅在内存中存在。
通过Intent传递Parcelable对象
Intent.putExtra(key,Parcelable);
创建序列化类:
public class CityVPN implements P arcelable {
public String vpn_type_brand="";
public int vpn_type_status= -1;
public boolean selected;
public static final Parcelable.Creator<CityVPN> CREATOR = new Parcelable.Creator<CityVPN>() {
public CityVPN createFromParcel(Parcelin) {
return new CityVPN(in);
}
public CityVPN[] newArray(intsize) {
return new CityVPN[size];
}
};
public CityVPN(Parcel in) {
vpn_type_brand = in.readString();
vpn_type_status = in.readString();
selected= in.readByte() != 0;
}
@Override
publicintdescribeContents() {
return0;
}
@Override
public void writeToParcel(Parcel arg0,int arg1) {
arg0.writeString(privonce);
arg0.writeInt(vpn_type_status);
arg0.writeByte((byte)(selected? 1 : 0));
}
}