【问题标题】:Blackberry persistent store - no data saved after handheld restart黑莓持久存储 - 手持设备重启后没有保存数据
【发布时间】:2011-10-02 08:36:59
【问题描述】:

我正在尝试为黑莓编写一个应用程序并且我正在使用持久存储,但是当我重新启动设备时,数据丢失了。有人知道为什么会这样吗?
提前感谢大家!

    public static void add(Subscription s) throws IOException {
        Vector subscriptions = SubscriptionsController.getSubscriptions();
        if(subscriptions == null) subscriptions = new Vector();
        subscriptions.addElement(s);
        synchronized(SubscriptionsController.persistedSubscriptions) {
            SubscriptionsController.persistedSubscriptions.setContents(subscriptions);
            SubscriptionsController.persistedSubscriptions.commit();
        }
    }

【问题讨论】:

  • 请发布您正在使用的代码
  • @seand,我上面发布的代码实际保存了。

标签: blackberry java-me blackberry-eclipse-plugin persistent-storage


【解决方案1】:

我假设(总是一个坏主意哈哈)你有子类 PersistentStore /PersistentObject (因为你可以提交()等)? 是否实现了 Persistable(不被子类继承)?

【讨论】:

  • 嗨,丹。那正是我的问题。我保留了一个未实现 Persistable 接口的 Subscriptions 对象向量。现在它正在工作:)
  • 爱 CrackBerry :) 很高兴我能帮上忙!
【解决方案2】:

据我所知,SubscriptionsController 不是 Blackberry 类。看起来您的意外行为是由于此类的实现所致。

如果您希望在设备重置时保持对象状态,您需要使用PersistentStore API,它将对象序列化到 Blackberry 上的文件中。 RIM 网站上的This document 解释了PersistentStore 的使用

【讨论】:

  • SubscriptionsController 是我创建的一个类,其中persistedSubscriptions 被声明为静态变量。数据第一次被持久化(订阅对象的向量),但是当我重新启动时,它们被删除了。
  • 静态变量不会在黑莓重启时保持不变。如果你想持久化对象,你需要 PersistentStore api。我已经编辑了我的回复来说明这一点。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-24
相关资源
最近更新 更多