gpt4 book ai didi

java - 如何在 BlackBerry 中关闭全局对话框并显示另一个对话框?

转载 作者:行者123 更新时间:2023-12-01 13:30:47 25 4
gpt4 key购买 nike

当中间时间大于等于4分钟时,需要显示消息对话框。如果空闲时间大于或等于5分钟,我需要关闭第一个对话框并推送另一个应该自动出现的对话框5 秒后关闭。

这是我到目前为止所拥有的:

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);
}
}
}
};

我的代码的问题是第一个对话框永远不会在 else 子句中关闭,并且在手动关闭第一个对话框之前,不会显示第二个对话框。

如何使 else 子句中的代码正常工作?5秒后我应该如何关闭第二个对话框?我正在考虑为此设计一个计时器但我不知道这是否是最好的方法。

提前致谢!

最佳答案

我认为您的代码中有一个简单的编码错误,这可能会导致您的问题。每次你通过clockUpdated(),你都会创建一个新的对话框4Minutes。因此,当您使用dialog4Minutes.close() 关闭它时,您实际上是在关闭刚刚创建的窗口,而不是正在显示的窗口。这是一些示例(未编译,未测试)替换代码,指示我将如何执行此操作:

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;
}
}
}
}
}
};

我不确定是否需要“同步(UiApplication.getEventLock())”,因为我认为clockUpdated在事件线程上运行,但在这段代码中,它不会造成伤害。

关于你的另一个问题,关于如何处理 5 秒后关闭,请查看 Timer 类。如果用户确实确认了该对话框,您将必须编写 setDialogClosedListener 代码(我在示例中忽略了它)才能采取行动。

关于java - 如何在 BlackBerry 中关闭全局对话框并显示另一个对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21578986/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com