0

I'm having a object like this:

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);
    }
}

Before I pass this object via an intent every value is correct. After the passing the pk value and some string values are changed. For example the pk is 5 and after the passing it is changed to 3801203.

Can someone help me on this, because I don't see the problem.

user1007522
  • 7,858
  • 17
  • 69
  • 113
  • I think i see a slight error; try `pk = (Integer) pk.readValue(null);` in the constructor. I'm suspecting something to do with autoboxing of `int` to `Integer`, but I'm not sure there's no reverse action - to automatically convert an `Integer` to `int` – Shark Mar 02 '16 at 16:21
  • 2
    You read links but you are not writing them????? There is a mismatch... –  Mar 02 '16 at 16:21
  • oh i was wrong, it's most probably the links. – Shark Mar 02 '16 at 16:23

1 Answers1

2

You are reading the value of links without ever writing it to your parcel:

    links = in.createStringArray();

When using parcels, you need to make sure that you keep the same order when reading and writing.

Vincent
  • 76
  • 2