坚持Android上Parcelable对象 [英] Persisting a Parcelable object in Android

查看:102
本文介绍了坚持Android上Parcelable对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类在我的Andr​​oid应用程序,我做了Parcelable,以便它可以活动之间传递。

I have a class in my Android app that I've made Parcelable so that it can be passed between Activities.

我希望能够将该对象保存到文件系统。看来,既然我已经实现Parcelable,这将是有意义的管道,它的输出到文件系统,并稍后阅读。

I would like to be able to save this object to the filesystem. It seems that since I've already implemented Parcelable, it would make sense to pipe the output of this to the filesystem and read it back later.

有没有做到这一点的正确道路?或者,我必须实现Parcelable和Serialiazble如果我想通过双方之间的活动对象,也将其保存到文件系统?

Is there a correct way to do this? Or must I implement both Parcelable and Serialiazble if I want to both pass the object between Activities and also save it to the filesystem?

推荐答案

从<一个href=\"http://developer.android.com/reference/android/os/Parcel.html\">http://developer.android.com/reference/android/os/Parcel.html

包裹不是通用序列化机制。这个类(和用于将任意对象成包裹相应Parcelable API)被设计成一个高性能的IPC传输。因此,它不适合放置任何包裹数据中持久性存储:在任何的包裹数据的底层实现的改变可以使较旧的数据无法读取。

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.

这篇关于坚持Android上Parcelable对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆