开发者

GPS LocationListener and phone sleeping

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:

  1. Will phone go to sleep while such service is running?
  2. How can I save power in this stuati开发者_如何学Goon?

Thanks in advance!


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();


Will phone go to sleep while such service is running?

Yes.


How about a background Service that periodically gets launched using AlarmManager and goes back to sleep after persisting coordinates to a database or file?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜