0

I'm thinking of the best way to do this.

I have a set of id's and times. Each id contains more than one time (in the future). Users can select for which id's they would like to get notified.

I was able to use Notification manager and broadcast a notification at a future time. The problem is the times will be updated everyday for a id, so the notification manager should be able to look for changes in times and update itself (only for the id's the users subscribes to).

Should I write a service that runs in the background and sends notification by constantly checking aganist the times ? or is there a better way to do this ?

eg id's and times

id = 1, times = 10/15/2015 10:00, 10/15/2015 23:00

id = 2, times = 10/15/2015 12:00. 10/16/2015 19:00

Community
  • 1
  • 1
Jayaram
  • 839
  • 1
  • 14
  • 24

1 Answers1

0

For this kind of case, use AlarmManager to schedule a task everyday. Using Service to schedule a task may drains the power consumption and sometimes it gets killed by Android system to retain memory resources, because of Service itself is in idle state if no thread running on it.

To schedule a task using AlarmManager, you can do the following action:

alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
    // INTERVAL_DAY = schedule it everyday
    AlarmManager.INTERVAL_DAY, alarmIntent);
Anggrayudi H
  • 14,977
  • 11
  • 54
  • 87
  • I'm not creating a repeating alarm, because it happens at different times and it may not even trigger on some of the days. – Jayaram Oct 16 '15 at 03:05
  • @Jayaram, But you can cancel it by using `cancel()` method and change/re-schedule it programmatically. – Anggrayudi H Oct 16 '15 at 03:09