views:

218

answers:

2

I'm building a webapp for Android smartphones that runs with the OS internet browser. the main interface is to input datas. the data is added to a queue (android 1.5: gears, android 2.x: html5). Each 5 minutes (using setTimeout), the script looks if an internet connection is active, and if so, sends all the queue to the server.

If the phone is plugged on the wall and the webpage is ontop, the timeout works. if the browser is minimized or another application runs on top of it, the timeout doesn't work. if the phone is in sleep mode it doesn't work either.

can only native apps runs in background?

+1  A: 

can only native apps runs in background?

Certainly, I would not expect the browser to be waking up the device, for your sleep mode scenario. Apparently, based on your symptoms, they pause all Javascript threads when the browser itself is paused. That is not terribly shocking, given the battery problems that leaving those scripts running might cause.

CommonsWare
k, make sense, thank you!
Sirber
A: 

You could also base it on system time, rather than just setTimeout. That way it would at least run when they returned focus to the browser.

Michael Trotter
using `window.focus` event would make the code always execute
Sirber