Search code examples
javaandroidsqlitealarmmanager

Notification 5 minute before a float that's stored in a sqllite database android


I need some help with combining the alarm manager with values from a sqllite database. In my database I've stored a schedule with the column start_lesson (float). I want to get that value out of the database and send a message 5 minutes before star_lesson. Star_lesson could be something like this (9.30 , 10.20 etc.).

It need to check the whole day for a lesson that starts (and send a notification 5 minutes before).

So my question how could I do that?

Thanks in advance ;)


Solution

  • I would write a function that reads your database, finds the most imminent event, and then use AlarmManager to fire a PendingIntent at T-5 minutes.

    The PendingIntent would launch a BroadcastReceiver that would examine the database for all events due within the next five minutes, and notify the user in whatever way you think is appropriate.

    The BroadcastReceiver would then call the above-mentioned function to schedule the next alarm.

    In addition, all functions which might alter the database should also call this function to handle any possible schedule changes.

    You should also write a BroadcastReceiver to be triggered by the BOOT_COMPLETED broadcast and which will call the function. This makes sure everything gets restarted properly whenever the device reboots.