Android Learning Note--alarmmanager

Source: Internet
Author: User

Alarmmanager is called a global timer, and some are called alarms. In fact, it's a bit similar to the timer.

There are two similar uses:

(1) Perform an operation after a specified length of time (2) perform an operation periodically

Alarmmanager contains the main methods:

Cancels a registered timer that matches a parameter
void Cancel (Pendingintent operation)
Register for a new delay timer
void set (int type, long triggerattime, pendingintent operation)
Registering a repeating type of timer
void setrepeating (int type, long triggerattime, long interval, pendingintent operation)
Register a non-precision repeating type timer
void setinexactrepeating (int type, long triggerattime, long interval, pendingintent operation)
Setting the time zone
void Settimezone (String timeZone)

Alarmmanager objects are used in conjunction with intent, you can start an activity on a timed basis, send a broadcast, or open a service.

There are several types of alarms available on Android:

public static final int elapsed_realtime
After the specified delay, the broadcast is sent, but the device is not awakened. This type of alarm does not wake the system when the system goes to sleep. Until the next time the system wakes up to pass it, the time spent in the alarm is relative to the time it starts, including the sleep time, which can be obtained by calling Systemclock.elapsedrealtime (). The system value is 3 (0x00000003).

public static final int elapsed_realtime_wakeup
After the specified delay, send the broadcast, and wake the device//can wake the system, using the same elapsed_realtime, the system value is 2 (0x00000002).

public static final int RTC
This type of alarm does not wake the system at the specified moment, but does not wake the device//when the system goes to sleep. It is not delivered until the next time the system wakes up, the time spent in the alarm is absolute, and the time spent is UTC time, which can be obtained by calling System.currenttimemillis (). The system value is 1 (0x00000001).

public static final int rtc_wakeup
At the specified moment, the broadcast is sent, and the wake-up device//can wake the system, using the same RTC type, with a system value of 0 (0x00000000).

public static final int power_off_wakeup
Can wake up the system, it is a shutdown alarm, that is, the device in the shutdown state can also wake the system, so we call it shutdown alarm. Using the same method as the RTC type, the system value is 4 (0x00000004).

See Api/app/alarm/alarmcontroller instances

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.