Introduction and use of Android Alarmmanager (timer)

Source: Internet
Author: User

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)

Main types of timers:

public static final int elapsed_realtime

//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
//can wake up 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 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
//can wake up 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 up the system, so we call it shutdown alarm. Using the same method as the RTC type, the system value is 4 (0x00000004).

Alarmmanager Life cycle:

Repeating Alarmmanager Once the boot is running in the background (unless you execute the Cancel method), you can see in app management that the app state is running. "Force stop" can make Alarmmanager stop.

Try several task managers, can only reset the counter (really free memory), but can not turn off the timer, only the system's own "forced stop" worked.

Introduction and use of Android Alarmmanager (timer)

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.