本文介绍了Android Cordova后退事件未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我在Android应用中使用的是 Cordova(版本6.3.2)的"后退按钮"事件.但是,当单击后退按钮时,该应用程序将关闭,而不是触发后退按钮事件.有很多类似的问题,但由于没有任何帮助,我不得不再问一次.

I'm using "backbutton" event of Cordova (version 6.3.2) in my Android app. But when the back button is clicked, the app closes instead of triggering the backbutton event. There are many similar questions but I had to ask again as nothing helped me.

我的初始化脚本:

  var cordovaInit = function (){

    //To bootstrap the app manually once the device is ready
    var receivedEvent = function (){
        angular.bootstrap($('body'), ['myModule']);
    };


    var onDeviceReady = function (){
      console.log("Device Ready");
      receivedEvent('deviceReady');
      document.addEventListener("backbutton", function(e){
               // My Code here
      });
    };

    //call onDeviceReady when the device is ready
    this.bindEvents = function (){
        document.addEventListener('deviceReady', onDeviceReady, false);
    };

    //If cordova is present, wait for it to initialize, otherwise just try to
    //bootstrap the application.

    if(window.cordova !== undefined){
        this.bindEvents();
    }
    else{
        receivedEvent();
    }
  };

   $(function (){
     new cordovaInit();
   });

正如您在上面看到的那样,我正在 deviceReady 事件之后注册该事件,并且deviceReady事件运行正常.很感谢任何形式的帮助.预先感谢.

As you can see above that I'm registering the event after the deviceReady event and the deviceReady event is working fine.Any help is very much appreciated.Thanks in advance.

推荐答案

也存在此问题.对我来说,这个问题是日食.当我使用cordova命令行构建应用程序并将apk下载到Android设备时,它运行良好.

Had the problem too. For me the issue was in eclipse. When I built the app using cordova command line and downloaded the apk to an Android device, it worked fine.

在eclipse中,我还有其他版本的Cordova以前的项目.由于已经存在一个CordovaLib类,因此Eclipse并未从新项目中导入新类,这是错误的.然后,我编辑了新项目的属性,而且-也错了! -在"Android"->库"下添加了现有的(旧)CordovaLib.

In eclipse I had other projects with former versions of Cordova. As a class CordovaLib already existed, Eclipse didn't import the new one from the new project, which was wrong. Then I edited properties of the new project and - also wrong! - added the existing (old) CordovaLib under "Android" -> Library.

正确的方法是将新的CorodovaLib与项目一起导入,在导入过程中将其重命名(注意:在Mac上,您必须模糊名称字段以使Eclipse能够识别重命名.如果您仍然用光标单击导入"在名称字段中,新名称将在导入过程中忽略),以避免与较早的CordovaLib类发生名称冲突.因此,在项目的属性-> Android->库中,应包括新版本的CordovaLib.

The correct way instead is to import the new CorodovaLib together with the project, rename it during import (attention: on Mac you must blur the name field to make eclipse recognize the renaming. if you click 'import' with the cursor still in the name field the new name is beging ignored during import) to avoid a name conflict with the older CordovaLib class. So at the project's properties -> Android -> Library the new version of CordovaLib should be included.

这篇关于Android Cordova后退事件未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 19:36