我想结束我的PhoneGap的Android应用程序与下面的一段code的:
I'm trying to close my Phonegap Android app with the following piece of code:
document.addEventListener("backbutton", function () {
if ($('.screenshot').is(":visible")) {
if (confirm('Afsluiten?')){
setTimeout( function() { navigator.app.exitApp(); });
}
else {
'';
}
}
else {
$(".items , .screenshot").show();
$(".content , .openbrowser , .html5vid , .introtekst_gal" ).hide();
$(".terug").hide();
}
}, true);
它的工作原理一次:pressing后退按钮,然后确定关闭该应用程序,符合市场预期。
It works once: Pressing the back-button and then "Ok" closes the app, as expected.
但是,当我不喜欢这样,应用程序没有关闭了:
But when I do it like this, the app doesn't close anymore:
preSS后退按钮(弹出所示) preSS取消(弹出消失) preSS后退按钮(弹出所示) preSSOK(弹出消失和应用程序应该关闭,但没有)我在做什么错了?
你可以试试这个code:
you can try this code:
document.addEventListener("backbutton", function () {
navigator.notification.confirm(
'Do you want to quit',
onConfirmQuit,
'QUIT TITLE',
'OK,Cancel'
);
}, true);
function onConfirmQuit(button){
if(button == "1"){
navigator.app.exitApp();
}
}