在 Android 中实现可序列化
我想保存我的 Android 游戏状态,以便用户可以从他/她离开的地方继续玩。 我一直在阅读有关可序列化接口的内容,但有一些问题。
除了背景渲染和其他一些事情之外,我的游戏是在一个类中执行的。 让我解释一下这意味着什么。我有一个类 A,游戏的所有不同元素都存储在各种数组列表中,在 A 中。所以我有几十个类 B、C、D、E 的实例......全部被调用和更新(当屏幕更新)来自 A 类。
我的问题是我不确定什么需要可序列化。每个类 B、C、D..(即每个类?或者只是 A?我不明白为什么序列化 A 然后将输出保存在 SQLite DB 中不会存储所有数据。
I want to save my Android game state so the user can pick up and play from where he/she left off.
I have been reading about the serializable interface, but have some questions.
Aside from background rendering and a few other things my game is performed from one class.
Let me explain what that means. I have a class A, and all the different elements of the game are stored in various arraylists and such, in A. SO I have dozens of instances of classes B,C,D,E... all being called and updated (when the screen updates) from class A.
My problem is I am unsure what needs to be serializable. Every class B,C,D.. (i.e. every class? or just A? I don't see why serializing A and then saving the output in SQLite DB wouldnt store all the data.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
作为建议,您可能还需要查看 Berkeley DB Java Edition,特别是 DPL(数据持久层)API。与 SQLite 一样,它是一个事务保护、可恢复、快速、占用空间小的数据库库。然而,DPL 允许您直接保留您的类,这使得它成为 Java 应用程序开发人员更容易的选择。
这是描述 API 及其使用方法的技术白皮书。
Just as a suggestion, you may also want to look at Berkeley DB Java Edition, specifically at the DPL (Data Persistence Layer) API. Like SQLite, it's a transactionally protected, recoverable, fast, small footprint database library. However, the DPL allows you to directly persist your classes, making it a much easier choice for Java application developers.
Here's a technical white paper describing the API and how to use it.
如果你想序列化某个对象。然后看看这个 链接 使用其他对象代替此链接中指定的 hashmmap 对象。
if you want to serialize some object. then look at this link use other object in place of hashmmap object that has been specified in this link.