开发者

problem with back button

when i am pressing the back button a pop screen is displayed which shows three button save, discard and cancel button i don't want this开发者_如何学运维 screen to be popped up. is this possible.

Thanks in advance


The default behaviour of the back button is to save changes for dirty screens. Rewrite the onClose() method to overwrite the default behaviour.

    public boolean onClose() {
        int choice = Dialog.ask(Dialog.D_YES_NO, "¿Do you want to exit?", Dialog.YES);

        if (choice == Dialog.YES) {
             //write a close() routine to exit
            close();
        }   
        return true;
    }

You return true because you managed the ESC button pressed event. Review the Screen class docs.

You can also change the default behaviour of the ESC button rewriting the keyChar method as follows:

    protected boolean keyChar(char character, int status, int time) {
        if (character == Keypad.KEY_ESCAPE) {
            onClose();
            return true;
        }
        return super.keyChar(character, status, time);
    }

close() should be somenthing like:

public void close() {
    System.exit(0);
}


Override the onSavePrompt method. Then that screen will not come. Actually that popup screen will come only when something is changed on your screen. So it will ask you for the appropriate action.

    protected boolean onSavePrompt() {

    return true;

    }


Skip the saving prompt with it

protected boolean onSavePrompt() {
    return false;
}


Override onClose() method like this:

public boolean onClose() {
    close();
    return true;
}

you will not get that annoying alert message.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜