views:

38

answers:

0

Hi, I'm new to Android and Java programming so I would like to clear up couple of things. I've wrote a background service that every 10 seconds it verifies something and based on some conditions it executes something or 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 (don't know how much or how to measure this) on battery life. Now... I don't need the service to do anything while the screen is off, so I'm thinking to register the Screen OFF and Screen ON broadcast Intents, and on screen OFF to stop the timer (or better to stop the hole service?) and on screen ON to start the timer (or the service). All these because I believe that in this way my application/service will consume not so much of the battery's life. Please tell me if my logic is fine, if I'm wrong in some ways or if there are better ways to achieve this. Thank you!