I am using jQueryMobile and phoneGap for a cross-device mobile application. I use html 5 local storage to persist records that worked on by user.
I don't know which phoneGap event to catch just before application shut-down so I can make sure data is saved before shutdown completes.
Base on suggestion from naughtur, I tried both unload and beforeunload events, neither of them got fired during app shutdown. Following is my code snip:
function persistTasks(){
alert ("is unloading the app");
offlineTasklist.set("tasks", tasklist);
}
function init() {
document.addEventListener("unload", persistTasks, false);
login();
}
$(document).ready(init);
In need be, you can open Event Logs > Windows Logs > Application > Application events. Now under the General tab, look for The following application attempted to veto the shutdown. You will see the apps which stopped the shutdown.
1) View Shutdown and Restart Log from Event Viewermsc” (no quotes) and hit Enter. The Event Viewer windows will open. After that, navigate to Windows Logs > System on the left pane. Click on Filter Current Log on the right.
The main cause why this particular error message (“This app is preventing shutdown” appears) when applications with unsaved data are still opened inside your operating system.
I'm not 100% sure about using unload events, because those technically could (not sure if this happens in PhoneGap) also be fired when loading a different web page, i.e. going index.html to about.html inside your PhoneGap app.
At least for Android, you have access to resume and pause events. So you can do:
document.addEventListener('pause', function() { alert('this alert will show up in the background while your app is paused.'); }, false);
document.addEventListener('resume', function() { alert('this alert will show up when you open the app back up.'); }, false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With