Here are the steps to reproduce:
ionic start test sidemenu
ionic platform add android
In app.js add the code:
$ionicPlatform.registerBackButtonAction(function (event) {
alert("back button action handler");
event.preventDefault();
}, 999);
This code can be added in the .run method or in the $ionicPlatform.ready()
method - same result, not working
ionic build android
then ionic upload
-> or manually put the APK on a device[BUG] - the alert is not shown and history view navigation is performed. It's like this action that I try to register is not taken into consideration.
What am I doing wrong? I tried this code in a controller also, also e.stopPropagation()
or e.stopImmediatePropagation
still no success.
I have the latest Ionic (1.4.5) and Cordova 4.3.0, tested on some Samsung devices. In Ripple, it works ok.
try preventing the default first
$ionicPlatform.registerBackButtonAction(function (event) {
event.preventDefault();
alert("back button action handler");
}, 999);
Also the code 999 is perfectly valid, the codes 100, 200, 300, 400, 500 are just the priorities that ionic asigns to certain actions of the back button. I've used multiple times the priority 900, it just puts your backbutton on top of all other action.
More information in the documentation : http://ionicframework.com/docs/api/service/$ionicPlatform/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With