Could it be something to do with timezones? Is there a better way?
AndroidJava
Last Comment
krakatoa
8/22/2022 - Mon
krakatoa
Although I don't do Android, it's extremely likely that your Timer resolution isn't right. Your code would certainly work. I ran it with a fixed rate schedule of 1000ms Period, and it was ok. I used a Timer handled by a separate class extending TimerTask.
mhdi
ASKER
Is there a better way?
The time/date of the alert changes based on other factors. I need to have an alarm go off if the time ever reaches the alert time/date.
Rather then run a timer constantly comparing like above, can I set an alarm in the android system? I would need the ability to remove and recreate the alarm if the alarm time changes before the time is reached.
krakatoa
I don't know if there are alarms you can set in Android. Nearly all I know is that a separate thread timer does work - cf: your comment that "nothing happens".
A separate thread has quite low running costs, at least on desktop Java.
So your requirement actually seems to include a dynamic alarm deadline, which might be redefined before the current alarm deadline is reached - is that right? That anyway sounds like a job for a separate thread responsible for updating the alarm params.
So your requirement actually seems to include a dynamic alarm deadline, which might be redefined before the current alarm deadline is reached - is that right?
That is correct.
(From where is the alarm deadline issued?)
The time and date comes from a webservice. The web service is automatically called every 10 minutes. Occasionally (every few hours) the alarm deadline changes.