sencha touch中处理Android返回按钮事件

应用中只有一个NavigationView的情况: 
// 处理一下android返回按钮
    document.addEventListener("deviceready", onDeviceReady, false);

    function onDeviceReady() {
      document.addEventListener("backbutton", onBackKeyDown, false);
    }

    function onBackKeyDown() {
      var canPop = false;
      var id = Ext.Viewport.getActiveItem().id;
      if (id.indexOf("login") != -1) {
      } else if (id.indexOf("mainview") != -1) {
        var mainview = Ext.Viewport.getActiveItem();
        var length = mainview.getItems().length;
        if (length > 2) {
          canPop = true;
        }
      }
      if (canPop) {
        console.log("canPop");
        ChinaFertilizer.app.getController("MainController").pop(1);
      } else {
        Ext.Msg.confirm("提示", "您确定要退出应用吗?", function(e) {
          if (e == "yes") {
            navigator.app.exitApp();
          }
        }, this);
      }

    }
在Ext.tab.Panel下有多个NavigationView的情况: 
// 处理一下android返回按钮
    document.addEventListener("deviceready", onDeviceReady, false);

    function onDeviceReady() {
      document.addEventListener("backbutton", onBackKeyDown, false);
    }

    function onBackKeyDown() {
      var item = Ext.Viewport.getActiveItem();
      var id = item.id;
      if (id.indexOf("mainView") != -1) {
         var mainview = Ext.Viewport.getActiveItem();
//				 var mainview = Ext.getCmp('moreView').getActiveItem();
         var length = mainview.getActiveItem().getItems().length;
         console.log("length = " + length);
         if(length > 2){
           if(app.viewId == 0){
             app.getController("phone.MyAppControllerP").pop(1);
           }else if(app.viewId == 1){
             app.getController("phone.TodoControllerP").pop(1);
           }else if(app.viewId == 2){
             app.getController("phone.AppCenterControllerP").pop(1);
           }else if(app.viewId ==3){
             app.getController("phone.MoreControllerP").pop(1);
           }
         }else{
           if (typeof WL === 'undefined') {
             Ext.Msg.confirm("提示", "您确定要退出应用吗?", function(e) {
               if (e == "yes") {
                 navigator.app.exitApp();
               }
             }, this);
           } else {
             WL.SimpleDialog.show("提示", "您确定要退出应用吗?", [ {
               text : "确定",
               handler : function() {
                 navigator.app.exitApp();
               }
             }, {
               text : "取消",
               handler : function() {
               }
             } ]);
           }
           
         }
       }else{
         if (typeof WL === 'undefined') {
           Ext.Msg.confirm("提示", "您确定要退出应用吗?", function(e) {
             if (e == "yes") {
               navigator.app.exitApp();
             }
           }, this);
         } else {
           WL.SimpleDialog.show("提示", "您确定要退出应用吗?", [ {
             text : "确定",
             handler : function() {
               navigator.app.exitApp();
             }
           }, {
             text : "取消",
             handler : function() {
             }
           } ]);
         }
       }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值