Klaus Heywinkel
Klaus Heywinkel

Reputation: 509

Codenameone: How to prevent the android hardware-back-button to exit the app?

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?

Upvotes: 2

Views: 807

Answers (3)

Shai Almog
Shai Almog

Reputation: 52770

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

Upvotes: 2

Anurag Aggarwal
Anurag Aggarwal

Reputation: 247

  @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

Upvotes: 2

OBX
OBX

Reputation: 6114

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!

Upvotes: 1

Related Questions