a.
Synchronize on the object.
b.
Invoke
commit()
as necessary. If any commit in the batch fails, the entire batch transaction fails.
5.
To commit a monitor object separately from a batch transaction, invoke
forceCommit()
while synchronizing the
monitor object.
Retrieve persistent data
1.
Import the following classes:
•
net.rim.device.api.system.PersistentObject
•
net.rim.device.api.ui.component.Dialog
2.
Invoke
getContents()
on a
PersistentObject
.
3.
To convert to your desired format, perform an explicit cast on the object that
PersistentObject.getContents()
returns.
synchronized(store) {
String[] currentinfo = (String[])store.getContents();
if(currentinfo == null) {
Dialog.alert(_resources.getString(APP_ERROR));
}
else {
currentusernamefield.setText(currentinfo[0]);
currentpasswordfield.setText(currentinfo[1]);
}
}
Remove persistent data
If you delete the .cod file that defines a
PersistentStore
, then all persistent objects that the .cod file created are deleted.
1.
Import the following classes:
•
net.rim.device.api.system.PersistentStore
•
net.rim.device.api.system.PersistentObject
2.
To remove all persistent data from a BlackBerry® device application, invoke
PersistentStore.destroyPersistentObject()
, providing as a parameter a unique key for the
PersistentObject
.
3.
To remove individual data, treat the data as normal objects, and remove references to it. A garbage collection operation
removes the data.
Development Guide
Persistent data storage
47