2

我正在使用可序列化的类来保存 xml 解析器结果,但是当我读到它在 Android 中非常慢时,我改成了 parcelable 类。

现在,我想将内容可打包类保存到文件中。

我该怎么做?

谢谢。问候。

4

1 回答 1

21

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.

于 2013-03-17T03:57:05.490 回答