【发布时间】:2017-05-09 23:54:09
【问题描述】:
我在我的 Android 应用中使用 Cordova(版本 6.3.2) 的“backbutton”事件。但是当点击后退按钮时,应用程序关闭而不是触发后退按钮事件。有很多类似的问题,但我不得不再次问,因为没有任何帮助。
我的初始化脚本:
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 事件工作正常。 很感谢任何形式的帮助。 提前致谢。
【问题讨论】:
-
要检查此问题是否仅与
backbutton事件有关,我尝试添加volumeupbutton、volumedownbutton和menubutton。这些都不起作用。谁能帮我调试一下吗?
标签: android cordova back-button