I have an Android Phonegap (3.0) application that need to periodically poll a web API for data.
I would like to keep it alive, even when it is moved to the background. I followed the general advice in this post and implemented a WakeLock
with PARTIAL_WAKE_LOCK
level, which is being created in the application's onCreate method
pm = (PowerManager)this.getSystemService(Context.POWER_SERVICE);
wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, org.apache.cordova.CordovaActivity.TAG);
wl.acquire();
I also have a call to wl.release()
in onTerminate()
The behavior I see (with logging) is that the app will keep running (polling server data periodically) even when the screen goes dark. But when I switch to another forgraound app, the polling will stop withon a few minutes.
Update: I do have the required permission set in the manifest file
<uses-permission android:name="android.permission.WAKE_LOCK" />