2
votes

When I run my Codenameone-App on an android-device, pressing the hardware-back-button stops/exits my app. I added a back-Command to the form - but this does not work. The hardware-back-button works as expected, when I call a second form from the first form and press the hardware-back-button there (the second form closes and the first is shown).

How can I prevent, that the App exits when the hardware-back-button is pressed on the first form?

3

3 Answers

2
votes
  @Override
    public void onBackPressed() {
        // nothing to code
    }

You have to override onBackPressed method and keep it empty , then your app won't get exit when you press back button from the first screen

2
votes

Call form.setBackCommand(new Command("")); to disable the default minimize behavior on the Form.

1
votes

You can override the onBackPressed() to handle the back button click :

@Override
public void onBackPressed() {
}

Leaving it as such, would make your app non responsive to back button. If I understood the question correctly, that's what you are trying to achieve!