Which event to catch for application shut down?
Posted
by
xueru
on Stack Overflow
See other posts from Stack Overflow
or by xueru
Published on 2011-01-13T06:46:36Z
Indexed on
2011/01/13
18:53 UTC
Read the original article
Hit count: 185
phonegap
|jquery-mobile
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);
© Stack Overflow or respective owner