开发者

Screen ON/OFF receivers on a service and battery life

I'm new to Android and Java programming, so I would like to clear up couple of questions I have.

I've written a background service that verifies something every 10 seconds, and, based on some conditions, it may execute something (or may not). This is implemented using a Timer.

My understanding until now is that the timer in the service will run even when the screen is off, so every 10 seconds, even with the screen off, the timer will fire up.

I suppose that this will have an impact on battery life, though I don't know how much or how to measure this.

Now, I don't need the service to do anything while the screen is off, so I'm thinking about registering the Screen OFF and Screen ON broadcast Intents.

On Screen OFF, the code would stop the timer – or would it be better to stop the whole service? – and on Screen ON it would start the timer (or service).

My thought on this direction is that my application will consume less of the battery than it would otherwise

Please tell me if my logic makes sense

If I'm wrong or if there are better ways to achieve this, please l开发者_如何学Pythonet me know.

Thank you!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜