Tips on mobile phone timed Service (Android Learning Guide 6)

Source: Internet
Author: User

 

Tips on mobile phone timed Service

 

1. The AlarmManager class provides a way to access the system's scheduled service, that is, developers can set an application in the program to be executed at a certain time in the future. When the scheduled time for AlarmManager is reached, the originally registered Intent object will be broadcast by the system and then start the target program.

 

2. scheduled service development steps:

 

A. Obtain the AlarmManager object, AlarmManager am = (AlarmManager) getSystemService (Service. ALARM_SERVICE );

 

B. Set the scheduled service,

 

Am. set (int type, long triggerAtTime, PendingIntent operation );

 

Operation (generally broadcast) is performed in triggerAtTime using the type calculation method ). Possible value of Type: ELAPSED_REALTIME (when the system goes to sleep state, this Type of alarm will not wake up the system. It is not passed until the system is wake up next time. The time used for this alarm is relative time, starting from the start of the system, including the sleep time. You can call SystemClock. elapsedRealtime. The system value is 3 (0x00000003) and ELAPSED_REALTIME_WAKEUP (which can wake up the system. The usage is the same as ELAPSED_REALTIME. The system value is 2 (0x00000002 )) RTC (when the system goes to sleep state, this type of alarm will not wake up the system. It is not passed until the System is wake up next time. The time used for this alarm is absolute time and UTC time. It can be obtained by calling System. currentTimeMillis. The system value is 1 (0x00000001), RTC_WAKEUP (which can wake up the system. The usage is the same as that of RTC, and the system value is 0 (0x00000000), POWER_OFF_WAKEUP (which can wake up the system, it is a Shutdown Alarm, that is, the device can also wake up the system when it is shut down, so we call it a Shutdown Alarm. The usage is the same as that of RTC. The system value is 4 (0x00000004 )).

 

Note: For more information about AlarmManager usage, see the android. app. AlarmManager class.


From tianshijianbing1989

Related Article

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.