tags:

views:

47

answers:

2

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 ?

A: 

It sounds like you need to create a Service.

Some details here

Eloff
Will that work and when you power off then turn on ? Do you have sample code ?
Dayanna
You will need to listen to the BOOT_COMPLETED intent: http://kfb-android.blogspot.com/2009/04/registering-for-timetick-after-reboot.html
Sotapanna
+3  A: 

Use AlarmManager, as it is designed for your use case -- your code being executed at scheduled times.

CommonsWare
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
@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