My app needs to grab some data from the web at a specific time each day. So I use an AlarmManager to schedule the task and that works ok.
But when looking at various
Reading your edit I presume you found out yourself: If you want to make sure that your service is started when using AlarmManager
, you better take the detour of first sending to a receiver and acquiring a wake lock there.
Otherwise it is possible that the phone will sleep before the requested service is launched.
That's what the javadoc of AlarmManager says and I also read it in post by Google engineer.
So now for your edit: When to acquire the lock?
The whole point of using the receiver is to acquire the lock within the onReceive()
method of the receiver, because Android will not fall asleep during the execution of this method.
For an example see this question.