Trevor
Trevor

Reputation: 1137

Executing Javascript in background using Phonegap

I've created an application that will need to fire Javascript events every "X" minutes. I'm using phone gap build to deploy on Android/iPhone/Blackberry, but I'm of course stuck, as the Javascript timer doesn't fire in the background (when they minimize the app). I was wondering if Phonegap had some sort of ability to fire Javascript events while the app is running in the background.

Or is there ANY way to accomplish this easily across these major phones? I just need to fire an ajax call with the geolocation info from the phones.

Upvotes: 9

Views: 7003

Answers (2)

Nico Westerdale
Nico Westerdale

Reputation: 2186

Yes you can do it, there's a PhoneGap plugin that does exactly what you need:

PhoneGap + Background.js https://github.com/jocull/phonegap-backgroundjs

Be careful configuring your config.xml

Upvotes: 2

swatkins
swatkins

Reputation: 13630

Currently, phone gap doesn't have this as an option. There are many requests out there for this sort of thing, but I think people are getting tripped up by the TOS for background events for iOS. Regardless, a phone gap plugin would do it as @Chase mentioned, but of course that requires native code writing.

I'm assuming you're wanting to push geo locations every x seconds/minutes so that your server knows where the phone is at any point in time (as long as the app is open or minimized)? That's one limitation of Loopt, is that it can't grab those locations in the background - hence the whole 'ping' action in the app.

Upvotes: 1

Related Questions