-
Notifications
You must be signed in to change notification settings - Fork 215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parent class CREATOR is miss when i parcelable with it in child class #55
Comments
Could you post some failing code? |
This Parent Class parcelabled ok : public class ResultInfo implements Parcelable {
@SerializedName("status")
protected Integer status;
@SerializedName("msg")
protected String msg;
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeValue(this.status);
dest.writeString(this.msg);
}
protected ResultInfo(Parcel in) {
this.status = (Integer) in.readValue(Integer.class.getClassLoader());
this.msg = in.readString();
}
public static final Parcelable.Creator<ResultInfo> CREATOR = new Parcelable.Creator<ResultInfo>() {
@Override
public ResultInfo createFromParcel(Parcel source) {
return new ResultInfo(source);
}
@Override
public ResultInfo[] newArray(int size) {
return new ResultInfo[size];
}
};
} When i parce the child class,child is ok: public class User extends ResultInfo{
protected String name;
protected Integer id;
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);
dest.writeString(this.name);
dest.writeValue(this.id);
}
protected User(Parcel in) {
super(in);
this.name = in.readString();
this.id = (Integer) in.readValue(Integer.class.getClassLoader());
}
public static final Creator<User> CREATOR = new Creator<User>() {
@Override
public User createFromParcel(Parcel source) {
return new User(source);
}
@Override
public User[] newArray(int size) {
return new User[size];
}
};
} But the parent class has been changed like this(public static final Parcelable.Creator CREATOR is missing): public class ResultInfo implements Parcelable {
@SerializedName("status")
protected Integer status;
@SerializedName("msg")
protected String msg;
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeValue(this.status);
dest.writeString(this.msg);
}
protected ResultInfo(Parcel in) {
this.status = (Integer) in.readValue(Integer.class.getClassLoader());
this.msg = in.readString();
}
} |
I think this problem may caused by CodeGenerator.java (the removeExistingParcelableImplementation method).It will delete it's parent CREATOR.Or you may want to delete child's CREATOR? /**
* Strips the
*
* @param psiClass
*/
private void removeExistingParcelableImplementation(PsiClass psiClass) {
PsiField[] allFields = psiClass.getAllFields();
// Look for an existing CREATOR and remove it
for (PsiField field : allFields) {
if (field.getName().equals(CREATOR_NAME)) {
// Creator already exists, need to remove/replace it
field.delete();
}
}
findAndRemoveMethod(psiClass, psiClass.getName(), TYPE_PARCEL);
findAndRemoveMethod(psiClass, "describeContents");
findAndRemoveMethod(psiClass, "writeToParcel", TYPE_PARCEL, "int");
} |
Hi, |
Hi, |
Hi @shibenli |
Hi, Parent Class impliment Parcelable, and i parcelable with it, it's ok.
But when i parcelable with it in child class,Parent's CREATOR is gone.i must reparcelable in Parent class.is it a bug?
The text was updated successfully, but these errors were encountered: