Repeating alarms with AlarmManager and daylight saving / leap years

by lorenz » Tue, 10 Feb 2009 06:40:09 GMT


Sponsored Links
 Hey

I'm looking for a way to trigger repeated actions. I'd like the user
to be able to choose the intervals at which these actions will be
executed. One should be able to choose from intervals like "Every
Day", "Every Month", and "Every Year". The setRepeating(int, long,
long, PendingIntent) method of the android.app.AlarmManager class only
supports a long value for choosing the interval between the execution
of the pending intent. My problem now is, that I can not just compute
the number of milliseconds that "fit into one day", since not all days
have the same length (daylight saving). This is also a problem for the
interval type "year" (leap years).

I had a quick look at the android.os.Handler class, but as I
understood the documentation I'd need to keep a service thread running
for my actions to be executed at some future time. I don't consider
that a good option for my needs ;-)

Is there anything in the API I could configure with a cron expression
or the like?

I was also thinking about scheduling an alarm with the AlarmManager
for a single execution at a given date/time and then having a receiver
that does the rescheduling according to a cron expression attached to
the intent. But I don't know if I just got something completely wrong
here and I'm reinventing the wheel with that approach :-/

Any advice or pointers would be greatly appreciated :-)

Cheers
Lorenz

--~--~---------~--~----~------------~-------~--~----~



Re: Repeating alarms with AlarmManager and daylight saving / leap years

by roberto » Thu, 10 Mar 2011 03:42:02 GMT


 Check out the BuzzBox SDK  http://hub.buzzbox.com/android-sdk/ 

You can actually use a cron string to schedule your task:

SchedulerManager.getInstance()
        .saveTask(this, "0 8-19 * * 1,2,3,4,5", YourTask.class);


I'm actively working on this, so I would love your personal feedback.
Roberto

-- 


Sponsored Links