在parcelable

时间:2016-03-02 16:16:40

标签: android parcelable

我有一个像这样的对象:

public class CommunityCurrencyContent implements Parcelable {
    private Double balance;
    private Long creationDate;
    private String description;
    private Double offerCount;
    private String communityIcon;
    private String communityDescription;
    private String communityName;
    private String[] links;
    private String code;
    private Double memberCount;
    private String communityImage;
    private Integer pk;

    public CommunityCurrencyContent(Parcel in) {
        balance = in.readDouble();
        creationDate = in.readLong();
        description = in.readString();
        offerCount = in.readDouble();
        communityIcon = in.readString();
        communityDescription = in.readString();
        communityName = in.readString();
        links = in.createStringArray();
        code = in.readString();
        memberCount = in.readDouble();
        communityImage = in.readString();
        pk = in.readInt();
    }

    public static final Creator<CommunityCurrencyContent> CREATOR = new Creator<CommunityCurrencyContent>() {
        @Override
        public CommunityCurrencyContent createFromParcel(Parcel in) {
            return new CommunityCurrencyContent(in);
        }

        @Override
        public CommunityCurrencyContent[] newArray(int size) {
            return new CommunityCurrencyContent[size];
        }
    };

    public Double getBalance() {
        return balance;
    }

    public Long getCreationDate() {
        return creationDate;
    }

    public String getDescription() {
        return description;
    }

    public Double getOfferCount() {
        return offerCount;
    }

    public String getCommunityIcon() {
        return communityIcon;
    }

    public String getCommunityDescription() {
        return communityDescription;
    }

    public String getCommunityName() {
        return communityName;
    }

    public String[] getLinks() {
        return links;
    }

    public String getCode() {
        return code;
    }

    public Double getMemberCount() {
        return memberCount;
    }

    public String getCommunityImage() {
        return communityImage;
    }

    public Integer getPk() {
        return pk;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeDouble(this.balance);
        parcel.writeLong(this.creationDate);
        parcel.writeString(this.description);
        parcel.writeDouble(this.offerCount);
        parcel.writeString(this.communityIcon);
        parcel.writeString(this.communityDescription);
        parcel.writeString(this.communityName);
        parcel.writeString(this.code);
        parcel.writeDouble(this.memberCount);
        parcel.writeString(this.communityImage);
        parcel.writeInt(this.pk);
    }
}

在通过intent传递此对象之前,每个值都是正确的。传递后,pk值和一些字符串值被更改。例如,pk为5,经过后,它变为3801203。

有人可以帮助我,因为我没有看到问题。

1 个答案:

答案 0 :(得分:2)

您正在阅读链接的价值而无需将其写入您的包裹:

    links = in.createStringArray();

使用包裹时,您需要确保在阅读和写作时保持相同的顺序。