Java Reference
In-Depth Information
you should remember to clean up after yourself as much as possible. You probably shouldn't
even keep a record store open over the lifetime of the MIDlet; after all, your MIDlet may be
paused by the device's application manager, and it would be unwise to have open resources
while the MIDlet is paused.
To find out all the record stores available to a particular MIDlet suite, call the
listRecordStores() method:
public static String[] listRecordStores()
Finally, to remove a record store, call the static deleteRecordStore() method. The record
store and its contained records will be deleted.
Note Record store operations, particularly opening and closing, may be time-consuming on actual devices.
You probably won't notice the delays using a desktop MIDP emulator, but on a real device, it may slow down
applications noticeably. (See http://www.poqit.com/midp/bench/ for some sobering measurements
from real devices.) For many applications, it may be appropriate to place record store access in its own thread, just
as network access goes in its own thread.
An additional consideration is that frequent read/write operations to the RMS can cause quite a drain on the
battery. A useful strategy for avoiding this problem is to cache records in memory and only write to the actual
persistent storage when a record is modified.
Sharing Record Stores
Record stores also have an authorization mode. The default authorization mode is
AUTHMODE_PRIVATE , which means that a record store is only accessible from MIDlets in the
MIDlet suite that created the record store. This is exactly as described earlier.
Record stores can be shared by changing their authorization mode to AUTHMODE_ANY , which
means that any other MIDlet on the device can access the record store. Be careful with this!
Don't put any secrets in an AUTHMODE_ANY record store. In addition, you can decide if you want
a shared record store to be writable or read-only.
You can create a shared record store using an alternate openRecordStore() method in the
RecordStore class:
public static RecordStore openRecordStore(String recordStoreName,
boolean createIfNecessary, byte authMode, boolean writable)
throws RecordStoreException, RecordStoreFullException,
RecordStoreNotFoundException
The authMode and writable parameters are only used if the record store is created, which
implies that the record store doesn't exist and createIfNecessary is true . You can change the
authorization mode and writable flag of an open record store using the following method:
public void setMode(byte authmode, boolean writable)
throws RecordStoreException
 
Search WWH ::




Custom Search