I know the performance difference between Parcelable (fast) and Serializable (slow). However, I need to store certain application information permanently, not only during one life cycle, so onSaveInstanceState and related methods using Parcelable objects are not suitable.
Therefore, I drew attention to Serializable . First of all, I have AbstractList types for storage - this is great, because they implement Serializable . However, many of the types that I store inside them are Parcelable , but not Serializable , for example. RectF .
I thought “no problem” since I can easily generate the parcel via Parcelable.writeToParcel(parcel, flags) , then call marshall() on it to create a byte[] that I can serialize and deserialize. I decided that I would use generics; create the SerializableParcelable<Parcelable> implements Serializable class, which allows a single-threaded solution for all the Parcelable types that I want to serialize. Then I, for example. save each RectF inside this shell in an ArrayList , and the lo-and-behold list and its Parcelable contents can be serialized.
However, the API docs state that marshall() should not be used for persistent storage:
public final byte [] marshall ()
Returns raw send bytes.
The data you extract here should not be placed in any permanent storage (on a local disk, on a network, etc.). To do this, you should use standard serialization or another common serialization mechanism. The Parcel marshalled view is highly optimized for local IPC and thus does not attempt to maintain compatibility with data created in different versions of the platform.
So now I'm stuck. I can either ignore this warning, or follow the route described above, or bypass the problem by expanding each individual Parcelable . I want to serialize and create special serialization methods, which seems extremely wasteful for time and effort.
Does anyone know the “right” shortcut to serialize a Parcelable object without using marshall() ? Or should I plow without listening to the warning? Maybe the SQLite database is the way to go, but I'm not sure and would like your advice.
Many thanks.