如何prevent的Android的关闭web应用时,后退按钮是pressed? [英] How to prevent Android from closing web-application when backbutton is pressed?
问题描述
我开发一个HTML5的web应用,并与科尔多瓦(PhoneGap的)1.7编译它。
I am developing a HTML5 web-application and compiling it with Cordova (phonegap) 1.7.
我要重写,而不是关闭应用程序(默认的Android)Android的后退按钮,这样我可以调用window.history.back()。如何从杀戮后退按钮pressed的defaultactivity prevent的Android?
I want to override the Android backbutton so that I can call window.history.back() instead of closing the application (default Android). How can I prevent Android from killing the defaultactivity on back button pressed?
我得到的pssed后退按钮$ P $ !!!!在logcat中,所以在应用程序被关闭的方法被激发。
I get the "Back button pressed!!!!" in logcat, so the method is fired before the application is closed.
这是我到目前为止有:
// Wait for Cordova to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
//
function onDeviceReady() {
document.addEventListener("backbutton", function(e) {
console.log("Back button pressed!!!!");
window.history.back();
}, false);
}
编辑:!我愿意直接从DefaultActivity.java机器人类接受一个答案解释的方式来模拟window.history.back()如果这是可能的。
I am willing to accept an answer explaining a way to simulate the window.history.back() directly from the DefaultActivity.java android class if that is possible!
推荐答案
我通过增加code以下的DefaultActivity.java文件,以prevent默认的机器人的行为,并保持JavaScript的解决我自己的问题code作为问题指出:
I solved my own question by adding the code below to the DefaultActivity.java file to prevent the default android behaviour, and keeping the javascript code as stated in the question:
@Override
public void onBackPressed() {
return;
}
我希望这可以帮助别人,将来有同样的问题!
I hope this helps someone in the future with the same problem!
这篇关于如何prevent的Android的关闭web应用时,后退按钮是pressed?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!