Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to schedule my android app to do something every hour

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,

like image 286
Marqs Avatar asked Sep 12 '10 18:09

Marqs


2 Answers

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.

like image 119
mtmurdock Avatar answered Oct 24 '22 13:10

mtmurdock


Just for the sake of completness, I am linking here the official docs, where the issue of the rebooting is adressed.

http://developer.android.com/training/scheduling/alarms.html#boot

like image 24
AlvaroSantisteban Avatar answered Oct 24 '22 15:10

AlvaroSantisteban