I just posted this question and someone suggested that I should look at another answer. In the other answer, it told me to put the enum into the parcel as a Serializable
. (And if you don't now what I am talking about, read the post above.) I tried to do it like this:
protected QuestionOptions(Parcel in) {
digitCount = in.readInt ();
operationType = (OperationType)in.readSerializable ();
boolean[] array = new boolean[1];
in.readBooleanArray (array);
timerEnabled = array[0];
}
public static final Creator<QuestionOptions> CREATOR = new Creator<QuestionOptions> () {
@Override
public QuestionOptions createFromParcel(Parcel in) {
return new QuestionOptions (in);
}
@Override
public QuestionOptions[] newArray(int size) {
return new QuestionOptions[size];
}
};
public QuestionOptions (OperationType operationType, int digitCount, boolean timerEnabled) {
this.operationType = operationType;
this.digitCount = digitCount;
this.timerEnabled = timerEnabled;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
boolean[] array = {timerEnabled};
dest.writeBooleanArray (array);
dest.writeInt (digitCount);
dest.writeSerializable (operationType);
}
When I run my app, it crashes with a RuntimeException
in the line:
operationType = (OperationType)in.readSerializable ();
in the QuestionOptions(Parcel in)
constructor. The error says "Parcelable encountered IOException reading a Serializable object (name = )". I tried searching this on SO and I see this question however that is about using lists and I have an enum. How can I do this?