开发者

How to use Parcelable if class requires additional parameters in construcor

开发者 https://www.devze.com 2022-12-30 18:38 出处:网络
I\'m trying to create class with generics that will have ability to serialize its state using Parcelable interface.

I'm trying to create class with generics that will have ability to serialize its state using Parcelable interface. The problem is that class has to contain constructor with single parameter - Parcel, but in my case I need to create class with additional parameters. Besides, Parcelable.Creator doesn't allow to use generics.

Here is an example:

public class Sample<T> {

...

public Sample(Context ctx开发者_开发问答, SomeInterface iface, Parcel parcel) {...}

...

}

What is the best practice to do it?


Already found the solution - I moved all members related to object state into separate Parcelable class and added the following constructor:

public Sample(..., ParcelableState state)

0

精彩评论

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

关注公众号