I have a base generic abstract class, lets call it Base<T> class.
This class extended by few subclass, with different types for T mData.
Let's say that I have class Sub1 extends Base<byte []> and class Sub2 extends Base<Object>.
In addition, I have a instancesList with type of List<Base<T>>, compounded from instances of Sub1 and Sub2.
- How can I parcel/un-parcel this list as a whole?
- Where should I implement the
Parcelableinterface? Where does theCREATORgoes, if any?
Normally you implement the reader (
CREATOR) and the writer in the concrete classes, not in the abstract class.When an instance of a concrete class is written to the
Parcel, the name of the concrete class is also automatically written to theParcel. When this is unparceled, the name of the concrete class is read, and the appropriateCREATORis called to create a new instance of that concrete class.There are some situations where you need to implement the reader and writer in the abstract class. In that case see Parcelable inheritance: abstract class - Which CREATOR? for more complex solutions.