BlackBerry
 





Home > Worldwide Developers > Java Knowledge Base Search > Knowledge Base Article

Java Knowledge Base

Knowledge Base Article

Saving your Data with RMS

Article Information: The MIDP RMS RecordStore implementation is used to store data persistently on the BlackBerry handheld. RMS stores data between application instances as well as after device resets. The javax.microedition.rms.RecordStore API is used for this.

The record store class enables you to store byte arrays to a named section of handheld storage. The data can then be retrieved directly from the record store in byte[] format using the record number (a unique ID given to each record as it is added). Additionally, functionality is provided to create an enumeration of all records in a record store.

To add a record to a RecordStore:

RecordStore recordStore = 
	RecordStore.openRecordStore(“FILE NAME”, true);

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

recordStore.closeRecordStore();

To retrieve an enumeration of the RecordStore:

RecordStore recordStore = 
	RecordStore.openRecordStore(“FILE NAME”, false);

RecordEnumeration e = 
	recordStore.enumerateRecords(null, null, false);

recordStore.closeRecordStore();

Although the RecordStore does not need to be closed until the object is no longer needed, it is good practice to close the RecordStore when you are not using it for an extended time, so that your data is always saved in the event that the program stops responding.


More Information:

       
 Legal | Copyright © 2002 Research In Motion Limited, unless otherwise noted.