Android Hardware backbutton callback handler doesn't work

Hi All,

I have following code in my controller. When I try hardware back button on android device. I don’t get any alert, rather navigates to pervious screen.

$scope.toRequests = function() {
       alert("BackButton CallBack");
};

    $ionicPlatform.onHardwareBackButton($scope.toRequests);

Please suggest how to avoid in navigating to pervious screen.

Thanks,
Venkat.

You have to overwrite default backbutton handling:

$ionicPlatform.registerBackButtonAction(function(e){
  // your handling
},100);

100 is the priority.

Hi,

Tried, Still doesn’t work.

    $ionicPlatform.registerBackButtonAction(function(e){
        alert("BackButton CallBack");
    },100);

Some more information,
Android OS that i am working is “kitKat” 4.4.

Thanks,
Venkat/

For the sake of debugging, could you try manually registering an event listener?

document.addEventListener(“backbutton”, function() {
alert(“BackButton CallBack”);
}, true);

Sorry its my mistake,

Included cardova.js in the index.html. Now working fine.

Thanks,
Venkat.