Detect Hardware back button press only on main page

Hi, can anyone please explain me how to use these two services
$ionicPlatform.on("backbutton") & $ionicPlatform.onHardwareBackButton

I have implemented this code

var deregister = $ionicPlatform.registerBackButtonAction(function () {  
          alert("Show on the home page")
}, 100
        );
 $scope.$on('$destroy', deregister)

in controller A. The problem is now the alert is shown in all views. I want to show a ionic popup when user presses back button when he is on main page.

Any help ?

Hi, i had the same situation, what i’ve implemented is a press back twice to exit the app, and have it on login screen, and also in the first view of the app (after login, user may remember his credentials so you won’t land in login page twice unless you logout).

In my case what i did is a directive to handle that: https://github.com/sonicd300/TNF-IonicUtils
Check the DblBackExit Directive.

Hope it helps.