当您按下 Android 设备中的硬件后退按钮退出 phonegap/ionic 应用程序时,有没有办法显示确认弹出窗口?
在当前状态下,我的应用在单击后退按钮后会继续返回到之前的状态。
无论您在应用程序的哪个位置,当您按下后退按钮时,是否有退出应用程序的方法?
我找到了这段代码,但它似乎不起作用:
$ionicPlatform.registerBackButtonAction(function() {
var confirmPopup = $ionicPopup.confirm({
title: 'Sign Out Confirm',
template: 'Are you sure you want to Logout?'
});
confirmPopup.then(function(res) {
if (res) {
$rootScope.rootScopeUserTransactionPassword = null;
$state.go('app.playlists');
} else {
console.log('You are not sure');
}
});
}, 100);
最佳答案
试试这个:
document.addEventListener('backbutton', function(event){
event.preventDefault(); // EDIT
navigator.app.exitApp(); // exit the app
});
希望对你有帮助。
关于android - 从 phonegap 中的 android 硬件后退按钮退出应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27395357/