Save parcelable class into file

2020-03-26 09:22发布

问题:

I was using a serializable class for I save the xml parser result, but when I read that It is very slow in Android, I changed to parcelable class.

Now, I want to save the content parcelable class into file.

How can I do it?

Thanks. Regards.

回答1:

According to Parcel API reference

Parcel is not a general-purpose serialization mechanism. This class (and the corresponding Parcelable API for placing arbitrary objects into a Parcel) is designed as a high-performance IPC transport. As such, it is not appropriate to place any Parcel data in to persistent storage: changes in the underlying implementation of any of the data in the Parcel can render older data unreadable.

Parcelable is meant for IPC use only and is not designed to be persisted. So you have to convert your object into some sort of persistable data structures like XML, JSON, Serializable.