0

I'm using Parcelable class to send Object from one activity to another activity in Android Java.

Parcelable only implements for me String data.

How I can read and write productsArrayList and status from this class?

public class Bill implements Parcelable {
    private String id;
    private Date createAt;
    private ArrayList<Products> productsArrayList;
    private ArrayList<StatusBill> status;

    public Bill(String id, Date createAt, ArrayList<Products> productsArrayList, ArrayList<StatusBill> status) {
        this.id = id;
        this.createAt = createAt;
        this.productsArrayList = productsArrayList;
        this.status = status;
    }

    protected Bill(Parcel in) {
        id = in.readString();
        createAt = new Date(in.readLong());
    }

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

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(id);
        dest.writeLong(createAt.getTime());
    }
    public static final Creator<Bill> CREATOR = new Creator<Bill>() {
        @Override
        public Bill createFromParcel(Parcel in) {
            return new Bill(in);
        }

        @Override
        public Bill[] newArray(int size) {
            return new Bill[size];
        }
    };
}
LeeHari
  • 31
  • 7
  • Does this answer your question? [Parcel List of List of Parcelable object](https://stackoverflow.com/questions/30562711/parcel-list-of-list-of-parcelable-object) – Peter O. May 23 '21 at 08:52
  • @PeterO. Sorry, it doesn't work for my situation – LeeHari May 23 '21 at 09:42

1 Answers1

0

I find a solution for all case when using Parcelable class

This website helps you to implement a Custom class to Parcelable class

Paste your Custom class in textarea and click Build button.

You will receive your Custom class implemnets Parcelable class

http://www.parcelabler.com/

LeeHari
  • 31
  • 7