0

I'm trying to make a reminder app in android.I have already written code that stores Date and time information for the reminder along with a reminder title.Now I want to notify the user at appropriate time about the reminder for that I was planning to use a service that would keep a track of systems current time and the time stored in the database.I have a confusion as how to do this. Can anyone pls suggest something.

The only way I can think of doing this is to retrieve all the row in the remainder table and constantly keeping of the system time to check whether it matches any of the one specified in the retrieved rows data.(But this i guess would be very much inefficient)

2 Answers2

0

You should use AlarmManager. You can check this question or google tutorial.

Community
  • 1
  • 1
Dmytro Danylyk
  • 19,684
  • 11
  • 62
  • 68
0

You should be using the AlarmManager to trigger events. You should not try to re-create this mechanism yourself (sounds like that is what you are planning to do).

The AlarmManager will trigger a service to do something at specific times or intervals:

Here is a good SO example: How to start Service using Alarm Manager in Android?

You can pass an Extra with your intent to id keep a handle to which notification is being triggered. Like in this SO question:

stackoverflow.com/questions/15731259/how-to-use-requestcode-in-pendingintents

Community
  • 1
  • 1
Booger
  • 18,579
  • 7
  • 55
  • 72
  • Even I thought of using Alarm Manager but the problem is that I want the Alarm Manager to notify the service about the trigger rather than the system as i need to get some additional information (ie rest of the info about the reminder)so is that possible ? – Abhijeet Sonawane Mar 31 '13 at 13:51
  • You just need to store the additional information somewhere in your app (SharedPreferences is easy if it is simple), then when the Alarm is triggered, you can match the reminder info up (you can use the second argument in the PendingIntent - requestCode to determine which reminder was triggerred). I am quite confident you need to use the AlarmManager, and there are lots of tutorials about this use case. Please remember to mark my answer correct. – Booger Mar 31 '13 at 14:11
  • Thanks...would try your suggestion and reply the status :) – Abhijeet Sonawane Mar 31 '13 at 14:21
  • Can u please let me know to use the requestCode can't find a proper explanation anywhere. This what Im planning to do 1)Providing the primary key value(ie id) as a requestCode for pendingIntent 2)Setting up a Alarm Manager to start a service that would retrieve rest of the info about the reminder from database So what I was is how to push the id from PendingIntent till the Service.(Is that possible) Help would be highly appreciated :) @Booger – Abhijeet Sonawane Mar 31 '13 at 15:07
  • Upon looking at this further, I think you might be better served to just add your unique id as an extra to the intent you are using for your PendingIntent. requestcode seems to be not well documented (which you know). I think adding the id as an 'would' be a better suggestion. I am going to add that as an answer (better than my original). – Booger Mar 31 '13 at 16:07
  • Thanks :) Would try to implement as per ur suggestion. – Abhijeet Sonawane Mar 31 '13 at 18:19