I need to start the service in order to perform a long operation every x minutes. For this I have AlarmManager. Reading documents in http://developer.android.com/reference/android/app/AlarmManager.html I found this:
The alarm manager holds the processor monitoring lock while the onReceive () alarm receiver is running. This ensures that the phone will not sleep until you finish working with the broadcast. When the onReceive () function returns, the alarm manager releases this lock. This means that the phone will sleep in some cases as soon as your onReceive () method is complete. If your alarm receiver is called Context.startService (), it is possible that the phone will sleep before starting the requested service. To prevent this from happening, your BroadcastReceiver and service will need to implement a separate tracking blocking policy to make sure the phone continues to work until the service becomes available.
So, how can I start the service from AlarmManager and make sure that it is running. I know how to use WakeLocks, but it makes no sense, I mean that I can use wakelock in the Service, but the document says "it is possible that the phone will sleep before the requested service is launched"
source
share