开发者

How to use Parcelable if class requires additional parameters in construcor

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜