I want to marshall and unmarshall a Class that implements Parcelable
to/from a byte array. I am well aware of the fact that the Parcelable representation is not stable and therefore not meant for long term storage of instances. But I have a use case where I need to serialize a object and it's not a showstopper if the unmarshalling fails because of an internal Android change. Also the class is already implementing the Parcelable
interface.
Given an class MyClass implements Parcelable
, how can I (ab)use the Parcelable
interface for marshalling/unmarshalling?
First create a helper class ParcelableUtil.java:
With the help of the util class above, you can marshall/unmarshall instances of your class
MyClass implements Parcelable
like so:Unmarshalling (with
CREATOR
)Unmarshalling (without
CREATOR
)Marshalling