I want to have a reminding function(by set reminding time) in my app ,using notification. And I get to know that there may used service, broadcast and alarmmanger,
How can I complete this function ?
I think there are two ways:
- use the service ,and the notification is in service
- use the service to send broadcast,and the notification is in broadcastReceiver
the first question:
- which way is right or better?
- how to use that alarmmanager ? is that like the Timer class in java?
Simplest and most efficient way would be to use AlarmManager for something like reminders. You will need to make a BroadCastReceiver that receives your alarm. Your receiver can make the notification, since the
onReceive()method of the receiver also takes in aContextparameter. To make the Alarm, you will have to get an instance of the AlarmManager Class, make a PendingIntent with what you need, then actually set the Alarm.Sample Code for setting an Alarm