如何在 Blackberry 中使用持久对象存储?
我想创建一个简单的 CRUD 应用程序来测试 Blackberry 的数据处理能力。
如何创建一个简单的保存功能?
I want to create a simple CRUD application to test out the data handling capabilities of the Blackberry.
How do I create a simple save function?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在此示例中,我将向量存储在持久存储中。
您必须提供一个商店 ID,该 ID 应该是 long 类型。我通常通过将完全限定的应用程序类名连接到某个字符串来创建它,使其在我的应用程序中独一无二。
从存储加载 Vector 的示例:
初始化此存储并将其首次保存到磁盘的示例:
如果要提交更改(也称为将更改保存到磁盘),则需要重复下面两行。设置内容(OBJ);和提交()。
您可以存储以下内容,而无需执行任何特殊操作:
@see : http: //docs.blackberry.com/en/developers/deliverables/17952/Storing_objects_persistently_1219782_11.jsp
要存储您自己的类,它们(以及所有子类)必须实现“Persistable”接口。我建议您这样做,因为卸载应用程序时这些存储会自动清理。这是因为,当存储中的“任何”引用的类名不再具有与其关联的应用程序时,操作系统会清理存储的对象。因此,如果您的商店仅使用字符串,则它永远不会被清理。
In this example I'm storing a vector in the persistent store.
You have to come up with a store ID, which should be of type long. I usually create this by concating the fully qualified Application's Class name to some string that makes it unique with in my application.
Example of loading a Vector from the store:
Example of initializing this store and saving it to disk for the first time:
If you want to commit changes (aka save changes to disk), you need to repeat the bottom two lines. setContents(OBJ); and Commit().
You can store the following without having to do anything special:
@see : http://docs.blackberry.com/en/developers/deliverables/17952/Storing_objects_persistently_1219782_11.jsp
To store your own Classes, they (and all sub classes) have to implement the "Persistable" interface. I recommend that you do this, as these stores get cleaned up automatically when your application is uninstalled. This is because the OS cleans stored objects up, when "any" referenced classname in the store no longer has an application associated with it. So if your store is only using Strings, it's never going to get cleaned up.