Arindam Mukherjee
Arindam Mukherjee

Reputation: 2285

Clicking back button is giving illegal state exception

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..

Upvotes: 1

Views: 379

Answers (1)

alishaik786
alishaik786

Reputation: 3726

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;

Upvotes: 2

Related Questions