Persistent Store data lost after session terminates in Blackberry application
-
18-09-2019 - |
Question
I am using persistent stores to store data in a Blackberry application. While I create objects and store it in persistent store in same session data is saved properly. But the data is not recovered from store in next session.
How do I fix this?
My code is as follows:
static TrialStore ts = new TrialStore();
static Vector data= new Vector();
synchronized (store) {
store.setContents(data);
ts = new TrialStore();
ts .setElement(TrialStore.USERNAME, username);
ts .setElement(TrialStore.PASSWORD, password);
data.addElement(ts);
store.commit();
}
Solution
You need to use the PersistentStore
class to get and store the persistable object, for example:
Vector data = (Vector) PersistentStore.getPersistentObject(KEY).getContents();
Once you have updated the data, you can store it using:
PersistentStore.getPersistentObject(KEY).setContents(data);
PersistentStore.getPersistentObject(KEY).commit();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow