0

In the app that I'm developing, I want to have re-occuring task on each Monday (possibly at 00.01 AM). The task is basicly as follows: I will connect to a web service, to check whether there is a parameter or a new file to be fetched in order to use with the app itself.

Also, I need to send some data, which is basicly some data evaluated on that week, and restart the process on an on again. After a ton of reading and so on, I think it may be more appropiate to use an AlarmManager implementation, since I do not see any need for using the UI etc (but I am open to suggestions, of course)

Probably the main question is that how can I easily schedule a task that when we are on the next week's Monday, at 00.01 AM or whatever, the system will check for Internet connection and if possible connect with that web services to send & retrieve data? The app is not supposed to be open I guess, but please note that the stored data is basic key value pairs in a preference file on that app.

Ugur
  • 15
  • 4

1 Answers1

1

The best approach for your case would be to use the AlarmManager. More info you can find here: http://developer.android.com/reference/android/app/AlarmManager.html

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

And here for a more extended example: Android: How to use AlarmManager

Hope this helps!!

Community
  • 1
  • 1
Dimitris Makris
  • 5,183
  • 2
  • 34
  • 54
  • Thanks man. By the way do you have anything on mind about what to do for setting the time values for it? Like I said, the starting point can be the first minute of Monday, which is a starting point of a week for my case, but I am not so sure how to calculate the time difference for it... – Ugur Sep 03 '11 at 17:47
  • You can use the Date api, set a date to the desired date you want, i.e. Monday 5 September 00:00:00 and then calculate how many seconds are until the next Monday in order to set the repeat interval. – Dimitris Makris Sep 03 '11 at 17:50