java - Android Parcelable - Write and read ArrayList< IA > when IA is a interface -


i have interface ia , class b , c implement them. both b , c implement parcelable well.

then have tricky part:

class d has arraylist< ia >. need insert both classes b , c in arraylist. share same structure "is-a" relation don't apply.

i need pass d 1 activity parcel.

i've tried write (arraylist<ia>) in.readserializable got ioexception. know if ia not interface problem easy, can't seem find easy solution this.

any ideas?

@suppresswarnings("unchecked") public d (parcel in) {     list = new arraylist<ia>();     (...)         list = (arraylist<ia>) in.readserializable      }  @suppresswarnings("rawtypes") public static final parcelable.creator creator = new parcelable.creator() {     public d createfromparcel(parcel in) {         return new d(in);     }      public d[] newarray(int size) {         return new d[size];     } };  public int describecontents() {     return 0; }  public void writetoparcel(parcel dest, int flags) {     (...)     dest.writelist(list); } 

    @suppresswarnings("unchecked") public d (parcel in) {     list = new arraylist<ia>();     (...)         //error -> list = (arraylist<ia>) in.readserializable      list = in.readarraylist(ia.class.getclassloader()); }  @suppresswarnings("rawtypes") public static final parcelable.creator creator = new parcelable.creator() {     public d createfromparcel(parcel in) {         return new d(in);     }      public d[] newarray(int size) {         return new d[size];     } };  public int describecontents() {     return 0; }  public void writetoparcel(parcel dest, int flags) {     (...)     dest.writelist(list); } 

Comments