Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.
How to access the RecordStore from different MIDlet Suites for read and write operations
Series 40 DP 2.0
Series 40 DP 1.1
Series 40 DP 1.0
Series 40 6th Edition FP1
Series 40 6th Edition (initial release)
Series 40 5th Edition FP1
Series 40 5th Edition (initial release)
Series 40 3rd Edition FP2
Series 40 3rd Edition FP1
Series 40 3rd Edition (initial release)
Series 40 2nd Edition
S60 5th Edition
S60 3rd Edition FP2
S60 3rd Edition FP1
S60 3rd Edition (initial release)
S60 2nd Edition FP3
S60 2nd Edition FP2
In the same way as in S60 devices, a 'Publish and Subscribe' type of mechanism can be simulated in Java ME using the Record Store API. The Record Store API is meant for creating a Record Store whose status can be made public or private for sharing the record store accross MIDlet suites or keep it private for one MIDlet suite, respectively.
When a record store is shared, a MIDlet can register for changes on the record store. Registration enables the MIDlet to get the following notifications about the changes in the store: record added, record modified, and record deleted.
The MIDlet which is the creator of a Record Store make it shareable or non-shareable. A MIDlet suite cannot decide on the mode (shareable/non-shareable) of a record store for which it does not own.
In this example, a MIDlet named 'RMSProducerMIDlet' from a vendor called 'NokiaDeveloper' decides to create a Record store named 'MyStore' and make it shareable by setting its mode to RecordStore.AUTHMODE_ANY. The information stored in the RecordStore is the current date.
A MIDlet called 'RMSConsumerMIDlet' is interested in getting updates about the 'MyStore'. It can open the record store by specifying the Record Store name, the Vendor name, and the MIDlet suite name. After opening, it can register for any updates on that record store. If it does not need any updates at a certain point of time, it can unregister itself from the updates, too.
On the producer side, the code can be as follows:
//open a record store for updates.
RecordStore myRecordStore = RecordStore.openRecordStore("ShareableRecordStore", true);
//set the mode of the record store.
//RecordStore.AUTHMODE_ANY enables the record store to be available outside
//the suite for other MIDlet. The second parameter denotes that
//the record store is shared in read-only mode so that other
//MIDlets would not be corrupting it.
//after this the producer MIDlet can do any updates on the record store
//such as add record, update record, or delete a record using the record
myRecordStore.setRecord(recordId, myUpdatedData.getBytes(), 0, myUpdatedData.getBytes().length);
On the consumer side, the code can be as follows:
//On the consumer side there needs to be an implementation
//of the RecordListener interface which demands to have 3
//functions to be coded:
//<b>1.public void recordAdded(RecordStore aRecordStore, int aRecId)</b>
//<b>2.public void recordChanged(RecordStore aRecordStore, int aRecId)</b>
//<b>3.public void recordDeleted(RecordStore aRecordStore, int aRecId)</b>
//where aRecordStore is handle to the store and aRecId is the Id of the
//open the record store by providing the details
RecordStore myRecordStore = RecordStore.openRecordStore("ShareableRecordStore","ProducerMidletSuiteVendor","ProducerMidletSuite");
//register for the updates
//here "this" denotes the object that implements RecordListener
//whenever the producer updates the record store the appropriate
//function (recordAdded/recordChanged/recordDeleted) shall be called
//when there is no need for updates, unregistration can be done