开发者

Extending Parcelable to read another Parcelable

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜