import android.os.Parcel;
import android.os.Parcelable;
/**
Parcelable比Serializable接口性能更高
可用于Intent的数据传输
序列化
永久性保存对象
通过序列化对象在网络中传递对象
通过序列化在进程中传递对象
Parcel able是使用内存传递,不能很好的保证数据的持续性在外界有变化的情况,大多数情况下使用Serializable
*/
public class Test implements Parcelable{
//第一个传入的值的类型,第二个执行时值的类型,第三个返回的值的类型
String
name;
protected Test(Parcel in) {
name = in.readString();
//在读取系列化的时候read
}
@Override
public void writeToParcel(Parcel dest,
int flags) {
dest.writeString(
this.
name);
//在生成序列化的时候写入
}
//下面部分都不需要处理
@Override
public int describeContents() {
return 0;
}
public static final Creator<
Test>
CREATOR =
new Creator<
Test>() {
@Override
public Test createFromParcel(Parcel in) {
return new Test(in);
}
@Override
public Test[] newArray(
int size) {
return new Test[size];
}
};
}