Reputation: 11
I've created service which has LocationListener in it. In order to keep service running the service is set as foreground. I have some questions about phone power management and sleeping in that circumstances:
Thanks in advance!
Upvotes: 1
Views: 1298
Reputation: 486
If you don't want the service to sleep then you can keep the device awake.
Snippet:
private PowerManager.WakeLock wakeLock; //member variable
somewhere in your service class:
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "some_tag");
When you're done running then you can do:
wakeLock.release();
Upvotes: 1
Reputation: 647
How about a background Service that periodically gets launched using AlarmManager and goes back to sleep after persisting coordinates to a database or file?
Upvotes: 0
Reputation: 1006674
Will phone go to sleep while such service is running?
Yes.
Upvotes: 0