public enum CouponType implements Parcelable {
UNKNOWN,
FIXED,
PERCENT;
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(ordinal());
}
public static final Creator<CouponType> CREATOR = new Creator<CouponType>() {
@Override
public CouponType createFromParcel(Parcel in) {
return CouponType.values()[in.readInt()];
}
@Override
public CouponType[] newArray(int size) {
return new CouponType[size];
}
};
}
在实体类中写入与读取时
//写入,writeToParcel方法中
dest.writeParcelable(couponType, flags);
//读取,构造方法中
couponType = in.readParcelable(CouponType.class.getClassLoader());