Skip to content Skip to sidebar Skip to footer

Trying To Retrieve Data From Parcel

I have an Order Object that contains an ArrayList of MenuItem Objects. Both classes implement the Parcelable interface. When I attempt to retrieve the object from the Intent in the

Solution 1:

I fixed my problem. The issue was as follows:

In the Order class.

public void writeToParcel(Parcel dest, int flags) {

    dest.writeInt(covers);

    dest.writeInt(table);

    dest.writeList(items);

}

should be:

public void writeToParcel(Parcel dest, int flags) {

    dest.writeInt(covers);

    dest.writeInt(table);

    dest.writeTypedList(items);

}

and

privatevoidreadFromParcel(Parcel source) {

    covers = source.readInt();

    table = source.readInt();

    source.readList(items, null);

}

should be:

privatevoidreadFromParcel(Parcel source) {

    covers = source.readInt();

    table = source.readInt();

    items = newArrayList<MenuItem>();

    source.readTypedList(items,  MenuItem.CREATOR);

}

Post a Comment for "Trying To Retrieve Data From Parcel"