I develop app for time alerting ( for example when you need to drink medicine - it repeats at time intervals ). How can I implement that service runs forever in background ? Is that possible at all ?
Will that work and when you power off then turn on ? Do you have sample code ?
Dayanna
2010-10-14 22:22:56
You will need to listen to the BOOT_COMPLETED intent: http://kfb-android.blogspot.com/2009/04/registering-for-timetick-after-reboot.html
Sotapanna
2010-10-15 11:07:52
+3
A:
Use AlarmManager
, as it is designed for your use case -- your code being executed at scheduled times.
CommonsWare
2010-10-14 22:11:25
One more question. I need to read values from db or file and then check if need alert. Is there any limit for time interval ?
Dayanna
2010-10-14 22:39:12
@Dayanna: Set an `AlarmManager` alarm for the earliest time. When that alarm goes off, schedule an alarm for the next time. If you add one to the database that is earlier than the earliest alarm, cancel the outstanding alarm and schedule a new one for the newer time.
CommonsWare
2010-10-14 22:40:40