如何关闭对话框全球以及BlackBerry显示另一个? [英] How to close a global dialog and display another in BlackBerry?

查看:112
本文介绍了如何关闭对话框全球以及BlackBerry显示另一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

这是我迄今为止:

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

我的code问题是,第一个对话框是从来没有else子句中关闭,
不显示所述第二对话,直到手动关闭所述第一对话。

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.

我怎样才能让正常工作else子句里的code?
我应该如何关闭5秒后,第二个对话框?我在想该定时器
但我不知道这是否是最好的方法。

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.

在此先感谢!

推荐答案

我觉得这是在code进行简单的编码错误,这可能是导致你的问题。每当你经历clockUpdated时间()创建一个新的dialog4Minutes。所以,当你去关闭它,用dialog4Minutes.close(),你实际上关闭您刚才创建的,不是被显示的之一。下面是一些示例(编译没有,未测试)更换code这表明我会怎么做:

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

我不知道的同步(UiApplication.getEventLock())需要的,因为我觉得clockUpdated在事件线程上运行,但在这个code,也不会受到伤害。

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.

至于您的其他问题,如何处理5秒后结束,看Timer类。你将不得不code中的setDialogClosedListener(我我的样本中都忽略不计),如果用户确实在事实上承认对话采取行动。

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.

这篇关于如何关闭对话框全球以及BlackBerry显示另一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆