This post doesn't go into great detail about using the AlarmManger or creating a notification. It merely shows how to use the 2 together to create a notifcation at a specified time. For more detail on these two topics check these earlier entries.
The first step is to create an activity that uses the AlarmManager to launch an event at a specified time.
This activity will create a 1-time alarm that will create a status bar notification. The notification will be displayed 1 minute after the onCreate() method gets called.
- To change when the notification is displayed you can modify the time of the Calendar object cal. Adding time to it or just setting the date to a particular day will work.
- To create a repeating alarm AlarmManager.setRepeating() or .setInexactRepeating() can be used. AlarmManager Reference
Next, a BroadcastReceiver is created to receive the event from our activity. When the event is received at the specified time, a notification will be created.
We can't forget to define the receiver in our manifest file. If we do, the event will not be handled and no notification will occur.
Finally, the activity to start when the notification is selected must also be defined. In this case it simply displays a Toast notification when the activity is created.