单击后退按钮给出非法状态异常

发布于 2025-01-08 06:31:04 字数 794 浏览 3 评论 0原文

在我的应用程序中,当我单击时,我会显示一个对话框。当我在该对话框中按“是”时,它给了我非法状态异常。但我想返回到上一个屏幕。如果我单击菜单并单击关闭,则会返回到上一个屏幕。以下是我的代码:

 public boolean keyDown(int keycode, int time) {

        if (Keypad.KEY_ESCAPE == Keypad.key(keycode)) {
            int result = Dialog.ask(Dialog.D_YES_NO, "Do you want to edit the list?");
            if (result == Dialog.YES) 
            {
                try
                {
                    UiApplication.getUiApplication().popScreen(this);
                }
                catch (Exception e) 
                {
                    e.printStackTrace();
                }
//              onClose();
            } 
            else 
            {
                return true;
            }
        } // end if

        return false;
    } 

请帮忙..

In my application, when i am clicking i showing a dialog. and when i am pressing yes in that Dialog, it is giving me the illegal state exception. But i want to go back in the previous screen. If i am clicking menu and clicking close, then it is going back to the previous screen. Below is my code:

 public boolean keyDown(int keycode, int time) {

        if (Keypad.KEY_ESCAPE == Keypad.key(keycode)) {
            int result = Dialog.ask(Dialog.D_YES_NO, "Do you want to edit the list?");
            if (result == Dialog.YES) 
            {
                try
                {
                    UiApplication.getUiApplication().popScreen(this);
                }
                catch (Exception e) 
                {
                    e.printStackTrace();
                }
//              onClose();
            } 
            else 
            {
                return true;
            }
        } // end if

        return false;
    } 

Please help..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薆情海 2025-01-15 06:31:04

当您单击设备中的后退按钮时,将调用默认的 onclose() 方法。所以,尝试这样做;

protected boolean onSavePrompt() 
{
    return true;
}
public boolean onClose() 
{
    int choose=Dialog.ask(Dialog.D_YES_NO, "Close the screen?");
    if(choose==Dialog.YES)
    {
        return super.onClose();
    }
    return true;
}

这是更好的方法;如果你像上面那样使用,那么你可能会遇到一个问题;那是:

如果您在第一个屏幕中使用该方法,那么根据弹出屏幕时的代码,则显示堆栈中没有屏幕(因为它是第一个屏幕);所以你可能会遇到这类问题;

试试这个;

When you are clicking the back button in the device then default onclose() method is called. So, try to do like this;

protected boolean onSavePrompt() 
{
    return true;
}
public boolean onClose() 
{
    int choose=Dialog.ask(Dialog.D_YES_NO, "Close the screen?");
    if(choose==Dialog.YES)
    {
        return super.onClose();
    }
    return true;
}

This is the better way; If you use like the above one then you may get one problem; That is:

If you are using that method in the first screen then according to your code when popup the screen then there is no screen in the display stack(Because it is the first screen); So you may get this type of problem;

Try this one;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文