Extending a class that implements Parcelable

后端 未结 3 1864
太阳男子
太阳男子 2021-01-11 09:54

I have a class, we\'ll call it class A, that implements Parcelable.

I have a second class, we\'ll call it class B, that extends class A.

My question is:

3条回答
  •  广开言路
    2021-01-11 10:35

    It is a little complex, but the trick is to use Reflection to get the types of subclass's members and to sort the members so that you can read and write the data back in the same exact order using the proper types.

    I have implemented the solution for class A here: https://github.com/awadalaa/Android-Global-Parcelable

    so now you can make any class parcelable by simply extending this class.

提交回复
热议问题