fancy
fancy

Reputation: 51393

PhoneGap/iOS disconnect on lost focus?

When my PhoneGap application gets push to the background and is there for sometime it disconnects from the server. If possible I would like to keep this connection open. If this is not possible I would at least like to be able to react to an event when focus in resumed so I can bring everything up to date.

Please let me know how best I can handle this.

Thanks!

Upvotes: 1

Views: 437

Answers (1)

Anders Lindahl
Anders Lindahl

Reputation: 42870

No, you cannot easily have a background thread running in javascript - when the application is pushed to the background, it ceases to execute.

You can however bind to the resume event to restore everything you need when your app is brought to front:

document.addEventListener("resume", onResume, false);

function onResume() {
   // restore context
}

Upvotes: 2

Related Questions