ionic2/3注册安卓返回

Posted 栴檀

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ionic2/3注册安卓返回相关的知识,希望对你有一定的参考价值。

如果使用了

this.app.getRootNav().push()以及this.navCtrl.push();
 
则在注册安卓返回键的时候
  registerBackButtonAction() {
        if (!this.nativeService.isandroid()) {
         return;
        }
        this.platform.registerBackButtonAction(() => {
         if (this.keyboard.isOpen()) {//如果键盘开启则隐藏键盘
            this.keyboard.close();
            return;
         }
         //点击返回按钮隐藏toast或loading或Overlay
         this.ionicApp._toastPortal.getActive() ||this.ionicApp._loadingPortal.getActive()|| this.ionicApp._overlayPortal.getActive();
         //隐藏modal
         let activePortal = this.ionicApp._modalPortal.getActive();
         if (activePortal) {
            activePortal.dismiss();
            return;
         }
         //页面返回
         if(this.app.getRootNav().canGoBack()){
             //this.showExit() this.nativeService.minimize()
                return this.app.goBack()
         }else{
                return this.showExit();
                
         }
        }, 10);
    }
//双击退出提示框
    showExit() {
        if (this.backButtonPressed) { //当触发标志为true时,即2秒内双击返回按键则退出APP
            this.platform.exitApp();
        } else {
            this.nativeService.showToast(‘再按一次退出应用‘);
            this.backButtonPressed = true;
            setTimeout(() => { //2秒内没有再次点击返回则将触发标志标记为false
                this.backButtonPressed = false;
            }, 2000)
        }
    }

以上是关于ionic2/3注册安卓返回的主要内容,如果未能解决你的问题,请参考以下文章

ionic2/3 禁止屏幕旋转,禁止横屏,竖屏

在 Ionic2 v3.4 中读取 SQLite SELECT 查询的结果

如何在 ionic 2 应用程序中访问角度全局?

Ionic 2 / 3:来自警报的数字输入

汇总 - 冲突的命名空间

Ionic 2/3 插件加载问题:可能来自 app.bundle.js