0

I am developing an android application using Cordova and Onsenui, in whic i want to disable the android back button handler. I've tried this answer ,but didnt work for me

Here is my code its placed on top of my app.js file

ons.ready(function() {
  ons.disableDeviceBackButtonHandler();

});
Community
  • 1
  • 1
shamon shamsudeen
  • 5,466
  • 17
  • 64
  • 129

1 Answers1

0

Supposing that you are using <ons-navigator var="myNavigator"></ons-navigator>, have you already tried something like this?

// To disable a navigator back button handler
myNavigator.getDeviceBackButtonHandler().disable();

You should also not forget to add cordova.js reference to your index page. You don't need to paste the file, it will be generated automatically every time you deploy a Cordova app.

<script src="cordova.js"></script>

If you don't add it, it will not be possible to manipulate the BackButton behavior.

Default behavior:

  • Main page: closes the app.
  • Other pages: goes back.

Disabling the handler, the app will be closed every time you press the button, regardless the page.

Andi Pavllo
  • 2,506
  • 4
  • 18
  • 30