我正在尝试使用 Parcelable 通过活动传递数据。这是我的代码:
public class Player implements Parcelable {
public static final Parcelable.Creator<Player> CREATOR = new Parcelable.Creator<Player>() {
public Player createFromParcel(Parcel in) {
return new Player(in);
}
public Player[] newArray(int size) {
return new Player[size];
}
};
private String name;
private List<Card> listCards;
public Player(String namePlayer) {
name = namePlayer;
listCards = new ArrayList<>();
}
private Player(Parcel in) {
// This order must match the order in writeToParcel()
name = in.readString();
in.readList(listCards, null);
// Continue doing this for the rest of your member data
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(name);
dest.writeList(listCards);
}
每当我运行此代码时,我都会收到错误:
java.lang.RuntimeException: Parcel: unable to marshal value com.antoinedelia.lebarbu_versionalcool.Card@ec54bb
您知道可能出现什么问题吗?
Thanks
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(name);
dest.writeList(listCards);
}
Since Card
类没有实现Parcelable
你不能做writeList/readList
。它仅适用于列表Parcelable
对象。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)