If all browser tabs/apps ran even in the background, it would absolutely hammer the battery life of the device. So operating systems and browsers are very strict about what can run in the background, for good reason: saving battery. Nobody wants an app to drain all their battery and many users will uninstall any apps they find wasting battery (and possibly give them a bad review).
The question here is, what are you trying to do?
If you want to play music in the background (e.g. music player app): you can enable playing in background on the Audio object.
If you want to simulate real-world time passing in the game: wait until the app wakes up, measure how much time it was asleep for, and then simulate that much time passing. That has the same effect and doesn't waste loads of battery.
If you want something else... what is it you're trying to do?
Thank you for your quick reply!
What I am trying to do is to get the (lat, long) positions of the user and storing it in a database. Basically, I am trying to do the following:
on location update -> AJAX passing lat, long parameters to MySql
The problem is that I would like to know the trajectory of the user... to check if he did it right or wrong (according to the game rules). The user can reach the right final position but I cannot evaluate if s/he followed the right path.
I do not need to call the ajax function on every location update if I can save it in a local file and submit it later. The point is that I need to record his trajectory and when the app is unfocused it stops getting users position.
Is there any way to do it?
Thanks a lot!