Ionic 2 - 如何在Android上使用后退按钮退出应用程序? [英] Ionic 2 - How to exit app with back button on Android?

查看:158
本文介绍了Ionic 2 - 如何在Android上使用后退按钮退出应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了当按下后退按钮时如何让Ionic2应用程序退出,但是我发现完全相反的问题,例如当按下后退按钮时如何防止退出Ionic2应用程序?。这就是我想要的,但是当我按下时它会在最近的标签之间切换。

I googled how to make Ionic2 app exit when back button is pressed, however I find totally opposite questions like "How to prevent exiting Ionic2 app when back button pressed?". This is what I want but it keeps switching between the recent tabs when I press back.

我刚用离子启动--v2 myProject标签开始了这个项目,并没有改变任何东西。

I just started the project with ionic start --v2 myProject tabs and didn't change anything.

如果在Android设备上按下后退按钮,我怎么强制它退出?

How can I force it to exit whenever back button is pressed on Android devices?

推荐答案

要按退回按钮退出应用程序,您必须在构造函数中注册硬件后退按钮,如下所示。

To exit the app on back button press, you have to register your hardware back button inside your constructor as follows.

constructor(){
    this.platform.ready().then(() => {
            this.platform.registerBackButtonAction(() => {
                navigator['app'].exitApp();                
            });
        });
}

但这适用于所有页面。要了解有关处理硬件后退按钮的更多信息,请 http://ionicframework.com/docs/v2 / api / platform / Platform /

But this will be applicable to all the pages. To know more about handling hardware back button check http://ionicframework.com/docs/v2/api/platform/Platform/

这篇关于Ionic 2 - 如何在Android上使用后退按钮退出应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆