Hi again guys. Still having problem with PGB migration to volt. Now the app exit prompt JS is not working on volt like it used to work on Phonegap Build.
Here´s the code, hope you can help us:
<script>
// Wait for device API libraries to load
//
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
// device APIs are available
//
function onDeviceReady() {
// Register the event listener
document.addEventListener("backbutton", onBackKeyDown, false);
}
// Handle the back button
//
function onBackKeyDown() {
navigator.notification.confirm(
'Are you sure you want to exit?!', // message
onConfirm, // callback to invoke with index of button pressed
'Confirm exit', // title
['Yes','No'] // buttonLabels
);
function onConfirm(buttonIndex) {
if (buttonIndex == 1) {
navigator.app.exitApp();
}
}
}
</script>
By the time the onload event has fired you’ve probably missed the deviceready event.
(I used to have a .js file that loaded and logged all the events when they fired and it was quite the eye opener.)
What I would do is to remove the onload event and just put this code in your index.html head
ok I understand what you mean. I meant that back button function worked fine after building it in pgb, which means it opened the popup prompting user to exit app, and now, after building using volt it just has the default back button behavior, which sends the app to background mode.
Code is pure javascript, did not change at all from one version to the other, but there must be something overriding regular behavior.
Thank you Phil, pretty clear as always!
I tried to test this but volt builder service says it is building for iOS despite having uploaded an android version (and of course pressing android button in placeholder builder page). Hope this can be fixed soon
Hi Phil, thanks for your help. First of all, the backKeyDown is just a name for the function, the trigger is called backbutton and don´t really know how to setup whether to apply it when it is down or up again.
Regarding options, the alert didn´t show up. Therefore, i´ve set just a body onload=“load()” function and add the backbutton event listener in there. Then, the alert did show up, but the back button event listener didn´t work as the back button acted as default. I´m really confused!!!