1

我正在尝试为黑莓手机编写应用程序,而且我正在使用持久性存储,但是当我重新启动设备时,数据丢失了。任何人都知道为什么会发生这种情况?
在此先感谢大家!黑莓持久性商店 - 手持重新启动后没有数据保存

 
    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(); 
     } 
    } 

+0

请发布您正在使用的代码 – seand 2011-04-18 07:44:46

+0

@seand,我上面贴的代码确实实际存储了。 – Olsi 2011-04-18 07:48:04

回答

2

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

+0

嗨丹。那正是我的问题。我坚持一个没有实现Persistable接口的Subscriptions对象向量。现在它的工作:) – Olsi 2011-04-18 20:05:17

+0

爱CrackBerry :) 很高兴我可以帮助! – Dan 2011-04-18 20:48:14

1

SubscriptionsController不是黑莓类,据我所知。看起来你的意外行为是由于这个类的实现。

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

+0

SubscriptionsController是我创建的类,其中persistedSubscriptions被声明为静态变量。数据第一次持久(一个Subscription对象的向量),但是当我重新启动时,它们被删除。 – Olsi 2011-04-18 08:56:15

+0

静态变量不会在黑莓重新启动时持续存在。如果你想持久化对象,你需要PersistentStore api。我已经编辑了我的回复来说这个。 – AndyT 2011-04-18 11:08:17