2
votes

I have a class that extends Parcelable, we'll call it Class A.

I have another class that extends Parcelable, we'll call it Class B.

One of the member variables of A is an ArrayList of Class B objects.

I'm trying to write the Parcelable overrides, but can't figure out how to save and read the ArrayList of Class B.

There are methods to read and write ArrayLists, but they want a parameter which is a ClassLoader and I am unfamiliar with it. I could also copy the ArrayList into an array and user the methods to read and write a Parcelable array, but this also requires a ClassLoader parameter.

Update:

It looks like

in.readTypedList(mList, ClassB.CREATOR);

and

out.writeTypedList(mList);

are what I'm looking for?

1

1 Answers

2
votes

You can pass null as ClassLoader to use the default one.

Parcel.readTypedList() and Parcel.writeTypedList() seem to be OK. Or you can use Parcel.readParcelableArray() and Parcel.writeParcelableArray() and convert the list to array.