How to use Parcelable if the class requires additional parameters in construction

I am trying to create a class with generics that will be able to serialize its state using the Parcelable interface. The problem is that the class should contain a constructor with only one parameter - Parcel, but in my case I need to create a class with additional parameters. Also, Parcelable.Creator does not allow generics.

Here's an example:

public class Sample<T> {

...

public Sample(Context ctx, SomeInterface iface, Parcel parcel) {...}

...

}

What's the best practice?

+2


a source to share


1 answer


A solution has already been found - I moved all the members related to the object state into a separate Parcelable class and added the following constructor:



public Sample(..., ParcelableState state)

0


a source







All Articles