i m trying to override hardware back button functionality. so,everything works fine with below code.
but,there are two $ionicModal in my app. As $ionicModal is opened and closed.Hardware back button stops working,app cannot closed with back button? Not even $ionicPlatform.registerBackButtonAction function is been called.
$state.$current.name == "";
var backbutton=0;
$ionicPlatform.registerBackButtonAction(function (event) {
if (($state.$current.name == "app.intro") ||
($state.$current.name == "app.main.home") ||
($state.$current.name == "app.account") ||
($state.$current.name == "app.myBusiness")||
($state.$current.name == "app.support")||
($state.$current.name == "app.noConnection")) {
if(backbutton==0){
backbutton++;
window.plugins.toast.showLongBottom('Press again to exit');
$timeout(function(){backbutton=0;},3000);
}else{
navigator.app.exitApp();
}
console.log("one");
}else if($state.$current.name == "app.welcome.takeControl") {
console.log("two");
$state.go("app.main.home");
}else{
console.log("three");
navigator.app.backHistory();
}
}, 100);
Thank you..
First check whether ionic modal instances which are opening are properly getting removed are not. Back button issue may occur if you are opening same modal instance twice but closing only once. So one instance of modal may not yet cleaned up.
In this case Hardware back button will try to Dismiss modal which is not yet cleaned up for each time rather than going to previous view. Since 'Dismiss modal' has higher priority(200) than 'Return to previous view'(100).
The priorities for the registerBackButtonAction are as follows:
To know more about $ionicModal
To know more about $ionicPlatform.registerBackButtonAction