Persistent Data and the Record Management System (RMS)
- The javax.microedition.rms Package
- Accessing Record Stores with the RecordStore Class
- Building an Address Book for J2ME Devices
- Conclusion
- Additional Resources
As I mentioned in previous articles, MIDP provides support for persistent data storage on mobile devices, and the MID profile specifies that compliant mobile devices must provide at least 8KB of non-dynamic memory for data storage purposes. In reality, most MIDP Java devices supply much more than this. This allows a midlet to take advantage of persistent data for applications. For developers with Java 2 Standard Edition experience, I should note that this data storage capability differs from Standard Java's serialization capabilities. The J2ME Record Management System (RMS) allows streams of data to be stored and accessed on a record-by-record basis. It's up to the application developer to parse each record down to the field level. Interfaces within the RMS package support comparison and retrieval functionality on an application-defined basis.
The javax.microedition.rms Package
J2ME's Record Management System is accessed via the javax.microedition.rms package. This package contains one class, RecordStore, and several useful interfaces (described in the following table):
Interface |
Description |
RecordComparator |
An interface defining a comparator that compares two records (in an implementation-defined manner) to see whether they match or what their relative sort order is. |
RecordEnumeration |
An interface representing a bi-directional record store record enumerator. |
RecordFilter |
An interface defining a filter that examines a record to see whether it matches (based on an application-defined criteria). |
RecordListener |
A listener interface for receiving record changed/added/deleted events from a record store. |
These interfaces are useful for implementing custom search-and-retrieval functionality. The interface that's used most often is RecordEnumeration. This interface is returned from the RecordStore.enumerateRecords() method call and is used to traverse a set of records returned from the record store. It includes methods such as nextRecord(), previousRecord(), numRecords(), and hasNextElement().