Java Reference
In-Depth Information
allows the MIDlet application to store persistent data within a controlled
environment, while maintaining system security. It provides a simple,
non-volatile data store for MIDlets while they are not running. The classes
making up the RMS are contained in the javax.microedition.rms
package.
Essentially, the RMS is a very small, basic database. It stores binary
data in a Record within a RecordStore . MIDlets can add, remove
and update the records in a RecordStore . The persistent data storage
location is implementation-dependent and is not exposed to the MIDlet. A
RecordStore is, by default, accessible across all MIDlets within a suite,
and MIDP extends access to MIDlets with the correct access permissions
from other MIDlet suites. When the parent MIDlet suite is removed from
the device, its record stores are also removed, regardless of whether a
MIDlet in another suite is making use of them.
Here is a short example of how to use RMS for writing and reading
persistent data from the device:
// saving data to RMS
public int saveToStore(byte[] data)
{
int recordID = 0;
try {
RecordStore store = RecordStore.openRecordStore("ImageStore", true);
recordID = store.addRecord(data, 0, data.length);
store.closeRecordStore();
} catch(RecordStoreException rse)
{
rse.printStackTrace();
} return recordID;
} // reading data from RMS
public byte[] loadFromStore(String storeName, int recordID) {
byte[] data = null;
try {
RecordStore store = RecordStore.openRecordStore("ImageStore", false);
data = store.getRecord(recordID);
store.closeRecordStore();
} catch(RecordStoreException rse)
{
rse.printStackTrace();
} return data;
}
For more about RMS, including searching and sorting records in a
RecordStore , refer to the MIDP documentation. Also download the
RMSWriter and RMSReader example applications from this topic's
website; they provide a fairly complete example of how to write, read
and share RecordStore s.
 
Search WWH ::




Custom Search