Search code examples
javaandroidlistparcelable

Writing a List to Parcelable?


I have a custom object that has private List<AnotherCustomObject> mList;. Note that AnotherCustomObject implements Parcelable.

However if I want to write mList to dest in writeToParcel() and then read it back later, is this the correct way:

dest.writeList(mList);

and then in the read method

in.readList(mList, ClassLoader.getSystemClassLoader());

Correct?


Solution

  • Please try to use necessary classloader.

    in.readList(mList, AnotherCustomObject.getClass().getClassLoader());