Troubleshooting guide
140
BlackBerry Java Development Environment Development Guide
Respond to deferred events
Task Steps
Provide a custom UI notification.
> Implement the NotificationsEngineListener interface.
private static class ListenerImpl implements NotificationsEngineListener
{...}
Define behavior if an event is
superseded by another event at the
same or higher priority level.
> Implement deferredEventWasSuperseded().
public void deferredEventWasSuperseded(long sourceID, long eventID,
Object eventReference, Object context) {
final long _eventID = eventID;
er = eventReference;
_app.invokeLater(new Runnable() {
public void run() {
NotificationsManager.cancelDeferredEvent(ID_1, _eventID, er,
NotificationsConstants.MANUAL_TRIGGER, null);
}
});
}
Define behavior if the BlackBerry®
device user inserts or removes the
BlackBerry device from the holster.
> Implement notificationsEngineStateChanged().
public void notificationsEngineStateChanged(int stateInt, long sourceID,
long eventID, Object eventReference, Object context) {
if(stateInt == notificationsConstants.OUT_OF_HOLSTER_ENGINE_STATE) {
// Perform action if the BlackBerry device is removed from the holster.
}
if(stateInt == NotificationsConstants.IN_HOLSTER_ENGINE_STATE) {
// Perform action if the BlackBerry device is inserted into the holster.
}
}
Define the notification when the
event occurs.
> Implement proceedWithDeferredEvent().
public void proceedWithDeferredEvent(long sourceID, long eventID, Object
eventReference, Object context) {
final long _eventID = eventID;
_app.invokeLater(new Runnable() {
public void run() {
String s = "This event has occurred: " + _eventID;
Dialog d = new Dialog(Dialog.D_OK, s, Dialog.OK,
Bitmap.getPredefinedBitmap(Bitmap.INFORMATION), 0);
d.show();
_eventHashtable.put(_eventID, d);
}
});
}
Register the notifications listener
with the NotificationsManager.
You can register only one NotificationsEngineListener for each application.
>Invoke registerNotificationsEngineListener(int,
NotificationsEngineListener)
, providing as parameters the event source ID of your
application and an instance of the class that implements the
NotificationsEngineListener
interface.
NotificationsManager.registerNotificationsEngineListener( ID_1, new
ListenerImpl(this));