Simple Alarm Clock implementation principle

Source: Internet
Author: User

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.

  1. intent intent = new  intent (mainactivity.this ,  alarmreceiver. class );   
  2. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.