我有以下课程:
public class E implements Parcelable {
@SerializedName("a")
private String a= null;
@SerializedName("b")
private BigDecimal b= null;
@SerializedName("c")
private String c= null;
@SerializedName("d")
private String d= null;
protected E(Parcel in) {
number = in.readString();
expirationYear = in.readString();
expirationMonth = in.readString();
}
public static final Creator<E> CREATOR = new Creator<E>() {
@Override
public E createFromParcel(Parcel in) {
return new E(in);
}
@Override
public E[] newArray(int size) {
return new E[size];
}};
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(number);
dest.writeString(expirationYear);
dest.writeString(expirationMonth);
}
}
如何包裹数据成员b?或者更好的是,如何包装盒装类型?
如您所见,writeToParcel方法错过了数据成员b以及受保护的c
。答案 0 :(得分:2)
How to use Parcelable on non-primitive types?
解决这个问题的一个好方法(在我看来)是创建扩展BigDecimal的类并在其上实现Parcelable接口。