Skip to content

Error writing a list of Parcelable objects with subclasses #66

@jtarnoff

Description

@jtarnoff

When I need to save a list of parcelable objects whose type has been subclassed, it doesn't save the members of the subclass.

class A {
  ArrayList<B> list;
  ...
}

class B {
  ...
}

class C extends B {
  // members in addition to members of class B that should be saved when saving list
}

This causes a difficult to trace RunTimeException when unparcelling the list. The RTE is something like

java.lang.RuntimeException: Parcel android.os.Parcel@XXX: Unmarshalling unknown type code YYY at offset ZZZ}

This happens because of the writeTypedArrayList method. I fixed the error by replacing this method with writeList and the readTypedArrayList method with readList as well.

Here is a larger writeup done by someone who experienced this same scenario without the plugin
https://medium.com/@kcoppock/writing-parcelable-lists-with-inheritance-a739c42c055c

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions