views:

132

answers:

2

Hi guys,

I want my app to access database every hour and read next record from the table then update desctop widget and send notification. I know that there is AlarmManager which I can use to register my Intents but they are deleted when the phone is turned off or rebooted.

Is there any other android class/service that I would update my application continuously even when I reboot my phone?

Thanks,

+1  A: 

take a look at the demo applications provided with android sdk

http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/AlarmService.html

the look at AlarmService_Service for the implementation of the service once the alarm has been triggered

http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/AlarmService_Service.html

Aaron Saunders
With respect to "but they are deleted when the phone is turned off or rebooted", you need to implement a `BOOT_COMPLETED` receiver to re-establish your alarms after a reboot. If you are implementing an app widget, you also have the option of using `android:updatePeriodMillis` in your app widget metadata -- this alarm is automatically managed for you, but it is not as flexible.
CommonsWare
A: 

put all of the background tasks you want to do in your app in Services which perform tasks in the background. In the service you should be able to define a timer that causes whatever updates you want to occur every x hours.

In the onCreate() of the widget, start the service. onCreate() is called every time that the widget comes to life (such as when the phone starts if it is on the home screen) and will therefore guarantee that the Service is always running.

Hope this was helpful.

mtmurdock
@mtmurdock: Having an everlasting service is a one-way ticket to a one-star rating on the Market.
CommonsWare
no, i never said an "ever lasting service" was a good idea, but @marqss said he wanted a service that was always running... even after the phone was reset.
mtmurdock