I need to get notified in code every X amount of time, even when the phone is sleeping.
So, My setup is a Service that sets a repeating alarm, and when it goes off it tells a BroadcastReceiver about it. From that receiver, I’m trying to start the same Service so that I can handle some code.
I don’t have any problem running it when the phone is awake or is debug mode.
However, when I’m not debugging and the phone is sleeping, it looks like the Service is not running so non of my Alarms is handled.
Where am I doing wrong?
I only want my app’s service to handle alarms periodically, even when the phone is sleeping (I moved to Alarms after having the same issues with a Timer object within the Service).
You need to acquire a wake lock.
http://www.vogella.com/blog/2011/02/07/android-wakelock/