對不起,這是太長了評論,所以我張貼作爲一個答案
由於Test1的擴展測試,測試應該haveit自己Parcelable實現。 這個實現是通過使用super
由其所有的「子」類調用的。例如(這是我在我的應用程序使用):
測試類
public class Tests implements Parcelable {
private int Id;
private String Name;
// parcelable
protected Tests(Parcel in) {
Id = in.readInt();
Name = in.readString();
}
public static final Creator<Tests> CREATOR = new Creator<Tests>() {
@Override
public Tests createFromParcel(Parcel in) {
return new Tests(in);
}
@Override
public Tests[] newArray(int size) {
return new Tests[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(Id);
dest.writeString(Name);
}
}
的Test1類
public class Test1 extends Tests implements Parcelable {
private int Score;
// parcelable
protected Test1(Parcel in) {
super(in);
Score = in.readInt();
}
@Override
public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);
dest.writeInt(Score);
}
@Override
public int describeContents() {
return 0;
}
public static final Creator<Test1> CREATOR = new Creator<Test1>() {
@Override
public Test1 createFromParcel(Parcel in) {
return new Test1(in);
}
@Override
public Test1[] newArray(int size) {
return new Test1[size];
}
};
}
來源
2016-05-10 01:45:35
kpo
什麼是您的測試類擴展? – AnixPasBesoin
'Tests'是否也可以實現parcelable? – kpo
它不從其他類擴展,除非我假設它的對象類java –