【发布时间】:2026-02-13 02:40:01
【问题描述】:
我正在尝试在 ionic 2 中处理我的 android 后退按钮,下面是我的代码,当用户从主页或登录页面单击时,它将让用户退出应用程序
let alert = this.alertCtrl.create({
title: 'Kmart',
message: 'Do you want exit kmart app ?',
buttons: [
{
text: 'Cancel',
role: 'cancel',
handler: () => {
this.logger.info("cancel clicked")
}
},
{
text: 'ok',
handler: () => {
this.platform.exitApp();
}
}
]
});
this.platform.registerBackButtonAction(() => {
console.log('back button pressed')
if (this.navCtrl.canGoBack()) {
console.log('nav can go back')
this.navCtrl.pop()
} else {
//here i have to show the alert for login and home page
alert.present();
}
}, 100);
上面这段代码放在我的home.ts文件中
我无法获取当前页面名称,因此我无法让我的应用退出。
当用户在主屏幕或登录屏幕上双击应用程序时如何退出应用程序。
【问题讨论】: