I haven't understood how to create the code needed to implement correctly the Parcelable for an object that contains GregorianCalendar objects.
E.g. fot an object User that contains String name; and GregorianCalendar creationDate;, my attempt is this:
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.name);
dest.writeParcelable(this.creationDate, flags);
}
private User(Parcel in) {
this.name = in.readString();
this.creationDate = in.readParcelable(GregorianCalendar.class.getClassLoader());
}
public static final Creator<User> CREATOR = new Creator<User>() {
public User createFromParcel(Parcel source) {
return new User(source);
}
public User[] newArray(int size) {
return new User[size];
}
};
that unfortunately doesn't work
in writeToParcel() at the line
dest.writeParcelable(this.creationDate, flags);
get writeParcelable cannot be applied to GregorianCalendar error
in
this.creationDate = in.readParcelable(GregorianCalendar.class.getClassLoader());
get Incompatible types error
How to code correctly the Parcelable?
0 comments:
Post a Comment