Ion RegisterBackButtonAction not working

Here are the steps to play:

  • Create the base ion project "ion test sidemenu launch"
  • Add the platform of the android platform "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 - the same result does not work

  • "ionic build android", then "ionic upload" → or manually, put apk on the device

[BUG] - the warning is not displayed, and viewing the navigation through the history is performed. This, how this action that I am trying to register, is not taken into account.

What am I doing wrong? I also tried this code in the controller, also e.stopPropagation () or e.stopImmediatePropagation still failed.

I have the latest Ionic (1.4.5) and Cordova 4.3.0 tested on some Samsung devices. Ripple is working fine.

+7
android ionic-framework ionic
source share
2 answers

try to prevent default first

 $ionicPlatform.registerBackButtonAction(function (event) { event.preventDefault(); alert("back button action handler"); }, 999); 

In addition, the code 999 is absolutely valid, the codes 100, 200, 300, 400, 500 are only the priorities that the ion assigns to certain actions of the "Back" button. I have used priority 900 several times, it just puts your backbutton on top of all the other actions.

Further information in the documentation: http://ionicframework.com/docs/api/service/ $ ionicPlatform /

+4
source share

Can you use code 999? Here is this information about 100, 200, 300, 400, 500, but not 900. http://ionicframework.com/docs/api/service/ $ ionicPlatform /

I am using code like 501, and this works.

Here is an example from my project that works

 $scope.$on("$ionicView.enter", function () { $ionicPlatform.registerBackButtonAction(registerBackButtonAction, 501); }); function registerBackButtonAction(e) { if (!!e && typeof e.preventDefault === 'function') { e.preventDefault(); } // some code return false; } 
0
source share

All Articles