- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
从事缓存项目。想用 Android 上的文件系统来做。我知道数据库也是一种选择,但想尝试文件系统。
在 Android 的情况下,使对象可序列化非常容易,使用 ObjectOutputStream 和 ObjectInputStream 来序列化和反序列化整个对象数组列表是自动发生的。
它还允许在两个 Activity 之间传递对象。但是,在读取 250 个节点的列表时,我的应用程序的加载时间增加了 5 倍。
我知道 parcelable 也执行传递部分,并且是 Android 的序列化方式。但是,任何人都知道如何将 parcelable 与 ObjectOutputStream 一起使用,以便可以充分利用 Android 的序列化。
此外,如果有人有想法如何加速 readObject 和 writeObject 的序列化,请分享。通过这样做可以实现多大的不同,这样做是否明智。
或者在 android 的情况下,数据库方式是缓存的唯一选择。不要忘记预缓存也可以通过 db 实现,但我们可以吗?
最佳答案
不要使用包裹。根据 Android 文档 (http://developer.android.com/reference/android/os/Parcel.html):
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.
让一个对象实现可序列化接口(interface)也是有风险的,因为那样你就被绑定(bind)到那个序列化格式。如果您将来更改该对象,您将在读取在旧制度下序列化的对象时遇到问题。
使用数据库可能是将内容缓存到磁盘的最佳选择。
关于java - 序列化与 Parcelable Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7731748/
我有两个 Activity,A 和 B。我试图将对象从 Activity A 发送到 Activity B。在 Activity A 中,我可以看到我的列表包含两个项目,但是当我在 Activity
我想在android中使用Parcelable而不是Serializable,因为它更快,推荐。我的问题是,我好像无法打包Java提供的类LinkedHashMap,对吧? 例如 public cla
我在为我的 Android 应用程序使用 parcelables 时遇到了一些问题。 我有一个名为 Transport 的自定义类,其中包含一堆 RoutePoint - 从文件加载并保存在数组中的实
编辑 清理和重建后,没有生成类 我在尝试使用 Parcels.wrap() 时遇到此错误 Unable to find generated Parcelable class for xyz.xyz.m
我有一个扩展 Parcelable 的类,我们称它为 A 类。 我有另一个扩展 Parcelable 的类,我们称之为 B 类。 A 的成员变量之一是 B 类对象的 ArrayList。 我正在尝试编
当我尝试使用 @Parcelize 注释 enum class 或 object 时,会导致错误 'Parcelable' should是一个类,既作为编辑器提示又作为编译失败。我可以 @Parcel
确实是相当简单的场景,但我在 Google 上找不到任何相关内容,所以这里是: class ContainerClass implements Parcelable { List _items;
我有一个实现Parcelable接口(interface)的类: class A implements Parcelable { } 我有另一个类 B 包含一个 A 对象作为实例变量。在类 B 内的
我如何实现写我的Set >使用通用数据类型到我的包裹? 这是我的代码.. dest.writeList(getArrTRA()); dest.writeList(ge
我有一个 Java Bean 类,在某些字段上用 @Parcel(Parcel.Serialization.BEAN) 和 Gson 的 @SerializedName 注释: 问题.java: @P
有时,我收到此错误,我不知道我的代码出了什么问题帮忙! 任何有帮助的建议代码。 这是我的错误报告: com.example E/UncaughtException: java.lang.Runtime
我正在实现具有另一个 Parcelable insde 的 Parcelable 类。 在 OuterParcelable 类中: @Override public void writeToParce
我想编码和解码一个实现 Parcelable 到/来自字节数组的类。 我很清楚 Parcelable 表示不稳定,因此不适合长期存储实例。但是我有一个用例,我需要序列化一个对象,它不是一个展示停止器如
有没有办法使用Parceler使用 Kotlin 数据类和构造函数进行序列化,而不为每个字段使用 @ParcelProperty 注释? 如果我尝试使用这样的库: @Parcel data class
我正在尝试编写一个可打包的数据对象,以便在我的 android 应用程序中从 activityA 传递到 activityB。 我的对象正在传递所有数据,除了我的可用服务类的 arraylist da
我在上课时遇到问题 Parcelable .问题是,我正在尝试将类(class)中的成员写入包裹,该成员是 ArrayList。目的。 ArrayList是 Serializable ,并且列表中的对
我有一个可打包的团队类 @Parcelize class Team(var name: String, var teamMembers: List, var id: UUID): Parcelable
我有一个包含另一个对象的对象,我想使用 Parcelable 将一个 fragment 发送到另一个 fragment ,例如: Fragment fragment = new Fragment();
Parceler 的自述文件指出它可以与其他基于 POJO 的库一起使用,尤其是 SimpleXML。 是否有任何示例可以证明其用法? 我已经成功地将 Parceler 与 GSON 结合使用: Gs
我是 android 的新手,在思考 Parcelable 界面时遇到了一些麻烦。 我终于找到了这个: https://stackoverflow.com/a/2141166/6647053 上述回答
我是一名优秀的程序员,十分优秀!