I've been reading on this matter but I have not found a solution yet.
I want to use the method onSavedInstance
to save an array of objects with the type Cell but all the objects inside the array will be children of Cell. My main problem is that I am not sure where to put my public static final Parcelable.Creator<MyObject> CREATOR
.
Parent:
public abstract class Cell implements Parcelable{
protected final int x;
protected final int y;
protected int conetion;
...
}
Children:
Frist:public class Block extends Cell {
private final Paint paint;
...
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeInt(describeContents());
out.writeInt(this.x);
out.writeInt(this.y);
}
}
Second:
public class Path extends Cell {
private final Paint paint;
private final boolean orientation;
private Type conected;
private int count;
...
@Override
public int describeContents() {
return 3;
}
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeInt(describeContents());
out.writeInt(this.x);
out.writeInt(this.y);
out.writeInt(this.conected.getColor());
out.writeInt(this.conetion);
out.writeInt(this.count);
}
}
Third:
public class Dot extends Cell {
private final Paint paint;
private Type conected;
private int count;
...
@Override
public int describeContents() {
return 2;
}
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeInt(describeContents());
out.writeInt(this.x);
out.writeInt(this.y);
out.writeInt(this.conected.getColor());
out.writeInt(this.conetion);
out.writeInt(this.count);
}
}
Fourth:
public class Path extends Cell {
private final Paint paint;
private final boolean orientation;
private Type conected;
private int count;
...
@Override
public int describeContents() {
return 3;
}
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeInt(describeContents());
out.writeInt(this.x);
out.writeInt(this.y);
out.writeInt(this.conected.getColor());
out.writeInt(this.conetion);
out.writeInt(this.count);
}
}
Thank you all for your time.
Carlos Morgado