Android Hardware backbutton callback handler doesn't work


#1

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.


#2

You have to overwrite default backbutton handling:

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

100 is the priority.


#3

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/


#4

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

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


#5

Sorry its my mistake,

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

Thanks,
Venkat.