I have a data structure MyObject
that implements the Parcelable
interface, and I want to pass a CopyOnWriteArrayList<MyObject>
object to a Bundle object to create a new Fragment. So I tried
Bundle args = new Bundle();
args.putParcelableArrayList("RssItems", rssItems);
But since CopyOnWriteArrayList is not a subclass of ArrayList, it does not match the method signature.
Is there any way to pass a CopyOnWriteArrayList to a Bundle object?
Think about it this way:
CopyOnWriteArrayList is simply a very special implementation of a list. You don't actually care about Parceling the implementation, you just care about Parceling up the contents of the list.
If you look at the Parcelable interface, you'll see that that is dead simple. In fact, you can probably copy the code (from AOSP) that parcels an ArrayList, directly.
While it is true that you can implement Serializable, it is no easier than implementing Parcelable and it is way slower.