I used Ionic in my app, but when I try to press the physical back button, it should exit the app, rather than back to last state.
I listened to $ionicPlatform.registerBackButtonAction event, and it does not execute.
app.js
app.run(function ($rootScope, $cordovaToast, $ionicPlatform, $state, $cordovaKeyboard) {
var deregister;
$ionicPlatform.ready(function () {
if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
StatusBar.styleDefault();
}
$ionicPlatform.registerBackButtonAction(function (event) {
event.preventDefault();
console.info('天啦噜,你终于执行了')
if ($state.current.name == "tab.discover") {
console.info('哈哈,要退出了')
navigator.app.exitApp();
}
else {
console.info('哈哈,要返回了')
navigator.app.backHistory();
}
}, 101);
});
ionic serve, i.e. is the problem really android-specific? - Eric Gopak