I think there is a simple coding error in your code, which may be contributing to your problem. Every time you go through clockUpdated() you create a new dialog4Minutes. So when you go to close it, with dialog4Minutes.close(), you are actually closing the one your have just created, not the one that is being displayed. Here is some sample (not compiled, not tested) replacement code which indicates how I would do this:
public static RealtimeClockListener clockListenerTest = new RealtimeClockListener() {
int _4Minutes = 60 * 4;
int _5Minutes = 60 * 5;
Dialog dialog4Minutes = null;
Dialog dialog5Minutes = null;
public void clockUpdated() {
synchronized (UiApplication.getEventLock()) {
UiEngine ui = Ui.getUiEngine();
if ( DeviceInfo.getIdleTime() < _4Minutes ){
// Shouldn't be needed - this is just for safety
if ( dialog4Minutes != null ) {
dialog4Minutes.close();
dialog4Minutes = null;
}
}
if ( DeviceInfo.getIdleTime() < _5Minutes ){
// Shouldn't be needed - this is just for safety
if ( dialog5Minutes != null ) {
dialog5Minutes.close();
dialog5Minutes = null;
}
}
if ( DeviceInfo.getIdleTime() >= _4Minutes && DeviceInfo.getIdleTime() < _5Minutes ) {
if ( dialog4Minutes == null ) {
// 4 minute Dialog has not been pushed yet
dialog4Minutes = new Dialog("Stay Logged In?", new String[] {"SI", "NO"}, new int[]{1,2}, 2, null);
ui.pushGlobalScreen(dialog4Minutes, 1,UiEngine.GLOBAL_QUEUE);
}
} else if ( DeviceInfo.getIdleTime()>=_5Minutes ) {
if ( dialog5Minutes == null ) {
// 5 minute Dialog has not been pushed yet
dialog5Minutes = new Dialog("You will be disconnected", new String[] {"OK"}, new int[]{1}, 1, null);
ui.pushGlobalScreen(dialog5Minutes, 1,UiEngine.GLOBAL_QUEUE);
if ( dialog4Minutes != null ) {
dialog4Minutes.close();
dialog4Minutes = null;
}
}
}
}
}
};
I am not sure the "synchronized (UiApplication.getEventLock())" is needed since I think clockUpdated runs on the Event Thread, but in this code, it won't hurt.
Regarding your other question, about how to handle the close after 5 seconds, look at the Timer class. You are going to have to code the setDialogClosedListener (which I have ignored in my sample) to take action if the user does in fact acknowledge the Dialog.