Arraylist in parcelable object

前端 未结 2 1320
傲寒
傲寒 2020-12-08 00:42

I have seen many parcelable examples so far, but for some reason I can\'t get it to work when it gets a bit more complex. I have a Movie object, which implements Parcelable.

相关标签:
2条回答
  • 2020-12-08 01:02

    From the javadocs for readTypedList:

    Read into the given List items containing a particular object type that were written with writeTypedList(List)

    at the current dataPosition(). The list must have previously been written via writeTypedList(List) with the same object type.

    You wrote them with a plain

    dest.writeList(reviews);
    
    0 讨论(0)
  • 2020-12-08 01:15

    reviews and authors are both null. You should first initialize the ArrayList. One way to do this is chain the constructor:

    public Movie (Parcel in) {
       this();
       readFromParcel(in); 
    }
    
    0 讨论(0)
提交回复
热议问题