When the iddle time is greater than or equal to 4 minutes, I need to display a message dialog. If the idle time is greater than or equals to 5 minutes, I need to close the first dialog and push another dialog that should be automatically closed after 5 seconds.
This is what I have so far:
public static RealtimeClockListener clockListenerTest = new RealtimeClockListener() {
public void clockUpdated() {
int _4Minutes = 60 * 4;
int _5Minutes = 60 * 5;
Dialog dialog4Minutes = new Dialog("Stay Logged In?", new String[] {"SI", "NO"}, new int[]{1,2}, 2, null);
dialog4Minutes.setDialogClosedListener(new DialogClosedListener() {
public void dialogClosed(Dialog dialog, int choice) {
//TODO
}
});
Dialog dialog5Minutes = new Dialog("You will be disconnected", new String[] {"OK"}, new int[]{1}, 1, null);
dialog5Minutes.setDialogClosedListener(new DialogClosedListener() {
public void dialogClosed(Dialog dialog, int choice) {
//TODO
}
});
synchronized (UiApplication.getEventLock()) {
UiEngine ui = Ui.getUiEngine();
if(DeviceInfo.getIdleTime()>=_4Minutes && DeviceInfo.getIdleTime() < _5Minutes){
ui.pushGlobalScreen(dialog4Minutes, 1,UiEngine.GLOBAL_QUEUE);
}else if(DeviceInfo.getIdleTime()>=_5Minutes){
dialog4Minutes.close();
ui.pushGlobalScreen(dialog5Minutes, 1,UiEngine.GLOBAL_QUEUE);
}
}
}
};
Problem with my code is that the first dialog is never closed in the else clause and the second dialog is not displayed until the first dialog is manually closed.
How can I make to work properly the code inside the else clause? And how should I close the second dialog after 5 seconds? I was thinking about a timer for that but I don't know if it's the best way.
Thanks in advance!