Close jQuery Android Application - Phone Book

I am trying to close the Android Phonegap application with the following code snippet:

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); 

It works once: pressing the back and OK button closes the application as expected.

But when I do it like this, the application no longer closes:

  • Click the back button (pop-ups)
  • Click cancel (popup disappears)
  • Click the back button (pop-ups)
  • Click "ok" (the popup disappears and the application MUST close, but does not)

What am I doing wrong?

+1
source share
2 answers

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(); } } 
+8
source

I had to break some of the code to check, so I ended up using:

  document.addEventListener("backbutton", function () { if (confirm('Afsluiten?')){ setTimeout( function() { navigator.app.exitApp(); }); } else { ''; } }, true); 

and that seems to work just fine. You have to do some console.logs to find out if the confirmation dialog will return the correct place. Also, what do you see in "adb logcat" when you start the application?

0
source

Source: https://habr.com/ru/post/905169/


All Articles