Android的Cordova-2.7.0我有以下JS脚本。Phonegap(科尔多瓦) - 后退按钮触发暂停事件,而不是Android中的后退事件
在测试后退按钮功能时,我遇到了一个奇怪的行为。
在应用程序的第一个跑,当我按下后退按钮“后退按钮”事件被触发并“onBackButton”函数被调用。
当我退出该应用程序并再次运行该应用程序,“onPauseButton”函数被调用按后退按钮之后,而不是“onBackButton”功能。
经过详细的研究,我意识到'navigator.app.exitApp();'(这是cordova函数)不会完全破坏Android应用程序。
如果我删除从最近使用的应用列表中的应用程序并再次运行它,“后退按钮”事件被触发,当我按下后退按钮“onBackButton”函数被调用。
因此,我想在应用程序的每次运行中捕获'backbutton'事件。
你建议我做什么?
感谢,V.H.
initialize: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
document.addEventListener('backbutton', this.onBackButton, true);
document.addEventListener('pause', this.onPauseButton, true);
},
onDeviceReady: function() {
console.log("onDeviceReady called");
},
onPauseButton: function() {
console.log("onPauseButton called");
},
onBackButton: function() {
console.log("onBackButton called");
console.log("current view: "+GUIManager.currentView);
if(GUIManager.VIEW_LOCALE == GUIManager.currentView){
GUIManager.showMatchListScreen();
} else if(GUIManager.VIEW_MATCHLIST == GUIManager.currentView){
navigator.app.exitApp();
}
}
这能帮助非常多。但有趣的是,设备不需要准备好进行'document.addEventListener'调用。它只将给定的监听器注册到文档对象内的给定事件类型。 – vaha 2013-05-14 08:30:50