I'm having test users say that my app is taking too much battery life on their android devices. I'm testing on a tablet (nexus 7) and in the Settings > App info > Permissions I see prevent tablet from sleeping
.
So does this mean that my app is keeping the device from sleeping or just that it can?
Regardless I need to find out how to make sure my app is not doing any background processing. How can I test this?
Note:
I'm using navigator.geolocation.watchPosition
and I'm concerned it's still running in the background, taking up more than needed resources.
Most likely the issue is the navigator.geolocation.watchPosition
.
You will want to make use of the device events to handle stopping and starting this when the app is paused and resumed.
Here is a quick sudo example:
Define a global for your watcher var watcher;
Add listeners for pause
and resume
:
document.addEventListener("pause", onPause, false);
document.addEventListener("resume", onResume, false);
When you start your watcher assign it to the global:
watcher = navigator.geolocation.watchPosition(onSuccess, onError, options);
Create onPause
and clear the watcher:
function onPause() {
navigator.geolocation.clearWatch(watcher);
}
If you want it to start again when the app is resumed, create onResume
and start it again:
function onResume() {
watcher = navigator.geolocation.watchPosition(onSuccess, onError, options);
}