0

I'm trying to control how the android hardware back button behaves in my app. I had it all working but now I can't reproduce it. The code I'm using is in app.js. I'm expecting the back button to do nothing but write to the console.

.run(function($ionicPlatform) {
  $ionicPlatform.onHardwareBackButton(function() {
    console.log("!!!!!!!!!!!!!!!!!!!!!!!!!!!")
  });

Can any one see what the problem is? I'm running ionic CLI v1.7.11. I'm running the code with ionic view on android

user1930848
  • 341
  • 1
  • 4
  • 12

2 Answers2

1

You can find full details, including a full working solution for both hard & soft back buttons at my related post:


To summarise how I handled the hardware back button, the trick is to register an action for the Back button, using code like this:

var doCustomBack= function() {
    // do something interesting here
};

// registerBackButtonAction() returns a function which can be used to deregister it
var deregisterHardBack= $ionicPlatform.registerBackButtonAction(
    doCustomBack, 101
);

$scope.$on('$destroy', function() {
    deregisterHardBack();
});

The actual setting is done in that second block calling $ionicPlatform.registerBackButtonAction().

This returns a method that can be called to deregister the action later on if you want to.

Community
  • 1
  • 1
Richard Le Mesurier
  • 29,432
  • 22
  • 140
  • 255
-1

It was a ionic view problem. Seems it does not support this.

user1930848
  • 341
  • 1
  • 4
  • 12