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