Record Listeners

In contrast to the desktop file system, it is possible to register listeners to record stores. A listener is informed whenever a record is changed in the record store it is registered to. This mechanism may be useful if different threads or different MIDlets of the same MIDlet suite are operating on one record store in parallel. A possible application could be some kind of automated logging service, writing records in the background. A MIDlet providing a GUI for the service could register itself as listener to the log record store when it is running in the foreground. Thus, it would be able to update its display of the log entries whenever a new record is added.

The corresponding RecordListener interface consists of the following three methods:

void recordAdded (RecordStore recordStore, int id)

is called when a new record with the given ID is added to the given record store.

void recordChanged (RecordStore recordStore, int id)

is called when the given record is changed.

void recordDeleted (RecordStore recordStore, int id)

is called when the given record is deleted.

A listener implementing these methods can be registered using the addRecordListener() method of the corresponding record store, where the only parameter is the RecordListener. You can unregister the listener by calling the removeRecordListener() method of the record store with the same listener as a parameter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset