Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I run a service method periodically?

I've an android service running, but I want to execute a specific service method every X hours to update data. What's the best aproach to do this without wasting android resources?

like image 379
Ferran Avatar asked Jun 21 '11 20:06

Ferran


1 Answers

Look into the AlarmManager.

Clarification: since you want the service method to run with hourly intervals, you do not want to keep your service process running all this time. By using the AlarmManager, the OS can kill the service when it is not needed, and then bring it up to execute the method when it is time.

like image 169
Peter Lillevold Avatar answered Oct 31 '22 17:10

Peter Lillevold