Would you like to tell us how we are doing?

You bet No thanks

Sorry about the red box, but we really need you to update your browser. Read this excellent article if you're wondering why we are no longer supporting this browser version. Go to Browse Happy for browser suggestions and how to update.

Storing data in the record store

The MIDP specification provides persistent storage for MIDlets. This mechanism is called the MIDP Record Management System (RMS), or record store. It is modeled after a simple record-oriented database. The record store is the MIDP equivalent of the RIM PersistentStore API. While it is designed for MIDlets, the record store can also be used in BlackBerry smartphone apps.

The RMS API is implemented in the javax.microedition.rms class.

The record store provides a simple record management system that allows you to create a data store object and persist a series of records within that object. Each record is a byte array, so you must serialize your data into a byte array format before storing it locally. Each byte array is assigned an integer ID that you use later to retrieve the byte array. Retrieval is done by enumerating over the records. The RMS API does not provide any inherent indexing or relationships between records.

Apps that use the record store can either make data private or allow sharing. The record store is frequently used to share data between apps.

Data that an app saves in a record store is automatically deleted when the app is removed. When you upgrade an app that uses the record store, the data is retained.

Here are the maximum storage sizes for the record store:

BlackBerry Device Software version

Maximum individual record store size

Maximum total record store size (cumulative for all apps)

Earlier than 4.1

64 KB

64 KB

4.1 to 4.5

64 KB

Available device memory

4.6 or later

512 KB

Available device memory

Create a record store

Import the javax.microedition.rms.RecordStore

Invoke openRecordStore(), and specify true to indicate that the method should create the record store if the record store does not exist.

RecordStore store = RecordStore.openRecordStore("Contacts", true);

Add a record to a record store

Import the javax.microedition.rms.RecordStore class.

Invoke addRecord().

int id = store.addRecord(_data.getBytes(), 0, _data.length());

Code sample: Adding a record to the record store

The following code sample shows you how to add a byte array using the RMS API.

int authMode = RecordStore.AUTHMODE_ANY;
boolean bWrite = true;

rs = RecordStore.openRecordStore( "rs", true, 
       authMode, bWrite );
  
byte[] pi = new byte[]{ 3, 1, 4, 1, 5, 9 };
int recordID;

recordID = rs.addRecord(pi, 0, pi.length);