There are questions about overriding the physical Android BACK button in Ionic, to provide custom behaviour:
Ionic v1 solution (out of date)
According to the Ionic docs for $ionicPlatform, the registerBackButtonAction()
returns:
A function that, when called, will deregister this backButtonAction.
This can be seen in the code for registerBackButtonAction()
:
// return a function to de-register this back button action
return function() {
delete self. [action.id];
};
So the correct way to deregister / cancel the custom behaviour is to call that function when the controller is destroyed:
var customBackButton = function() {
console.log("this is custom behaviour");
};
// registerBackButtonAction() returns a function which can be used to deregister it
var deregisterBackButtonAction = $ionicPlatform.registerBackButtonAction(
customBackButton, 101
);
$scope.$on('$destroy', function() {
deregisterBackButtonAction();
});
A more complete example showing how to override & restore the hard and soft buttons can be found here: