Writing arrays of Parcelables to a Parcel in Android

后端 未结 3 1789
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-12 21:31

I\'m trying to write an array of objects that implement Parcelable into a Parcel using writeParcelableArray.

The objects I\'m trying to write are defined (as you\'

相关标签:
3条回答
  • 2021-01-12 22:06

    Actually, you can extend an interface, and it looks like you need to do just that. The generics parameter in writeParcelableArray is asking for an extended interface (not the interface itself). Try creating an interface MyParcelable extends Parcelable. Then declaring your array using the interface, but the impl should be your Arrival extends MyParcelable.

    0 讨论(0)
  • 2021-01-12 22:25

    It turns out it just wanted me to build an array of Parcelables. To use the example from the question:

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        Parcelable[] a;
        /* 
            some stuff to populate "a" with Arrival 
            objects (which implements Parcelable) 
        */
        dest.writeParcelableArray(a, 0);
    }
    
    0 讨论(0)
  • 2021-01-12 22:25

    I know the problem is solved but my solution was other so I'm posting it here: in my case Eclipse automatically imported wrong package because of classes names abiguity(some dom.Comment instead of my Comment class).

    0 讨论(0)
提交回复
热议问题