tags:

views:

17

answers:

1

I'm creating a note application that notifies you at a certain time & date and I'm using a Timer object to schedule that notification. Basically, the user will input the note, time and date to be notified, and then will hit a submit button. Once that button is hit, a TimerTask is scheduled using the Timer class and this note will reflect on a ListActivity.

The problem I'm running into is this...

If the user decides to edit the note by changing the time and date to be notified, since the TimerTask was already scheduled, once the user hits submit, another TimerTask will be scheduled. Hence, there will be two notifications for the same note! I want to store the timer object somewhere so that when the note is to be edited, I can simply edit the timer object. This is my current approach but if you guys have any suggestions on how I can do this better that would be great!

A: 

Dump the Timer and TimerTask and use AlarmManager. Timer and TimerTask are fine for things with short periods that are only relevant while an activity is on-screen. AlarmManager is for longer periods, such as "time and date to be notified", because it allows your service to get out of memory.

CommonsWare