Android's Alarm

Source: Internet
Author: User

The difference between alarm and a timer is that alarm is operating outside the application. Even if the application is closed, they can still be used to activate application events or actions.

public void Createalarm () {//Gets a reference to alarm manager alarmmanager Alarmmanager = (alarmmanager) getsystemservice ( Context.alarm_service);//If the device is in hibernation, set ALARM to wake the device int alarmtype = alarmmanager.elapsed_realtime_wakeup;// 10 seconds after the device is triggered long time = 10000;//Create pending intentstring alarm_action = "alarm_action" capable of broadcasting and operation; Intent intentfofire = new Inten T (alarm_action); Pendingintent alarmintent = pendingintent.getbroadcast (this, 0, Intentfofire, 0);//Set Alarmalarmmanager.set (AlarmType , time, alarmintent);}

How do I cancel?

Cancellation of Alarmmanager.cancel (alarmintent);

How do I set up duplicates?

You can use the Setrepeting or Setinexactrepeating method of the alarm managerd.

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.