Reference from Literature http://jakend.iteye.com/blog/1980842
Simple alarm principle is the use of Alarmmanager set a time, time to send a broadcast, received the broadcast prompt time to.
The key is to get Alarmmanager object.
Alarmmanager manager = (Alarmmanager) getsystemservice (Alarm_service);
Look at the manager's method
The key method is the set method setting the date
The Long value in the first set method Triggeratmillis This is the trigger time, indicating that the time will prompt
the parameters in the second set method ong triggeratmillis trigger intervalmillis This periodic interval trigger event
Type a total of four types are as follows
ALARMMANAGER.RTC, the hardware alarm clock, does not wake up the phone (or other devices) hibernate, when the phone does not fire alarm when hibernating.
alarmmanager.rtc_wakeup, hardware alarm clock, when the alarm clock hair 躰 wake up the phone sleep;
Alarmmanager.elapsed_realtime, the real time passes the alarm clock, does not wake the phone to sleep, when the phone sleeps, does not emit the alarm clock.
Alarmmanager.elapsed_realtime_wakeup, real time elapsed alarm clock, when the alarm clock hair 躰 wake up the phone sleep;
The biggest difference between RTC alarms and Elapsed_realtime is that the former can trigger alarm events by modifying the phone's time, which passes through the real time, even in the dormant state, and the time is calculated.
Two set methods there is also a public parameter that is a pendingintent a deferred intent.
It's easy to get intent.
- intent intent = new intent (mainactivity.this , alarmreceiver. class );
- Pendingintent sender = Pendingintent.getbroadcast (mainactivity. this, 0, intent, 0);
Well, now that the fundamentals are clear, here's how the code is assembled.
The Manager object gives sender intent to register a recurring trigger event that is received by alarmreciever once triggered.
Full demo Download
Simple Alarm Clock implementation principle