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