Alarm manager development case for Android mobile phone alarm clock service
AlarmManager is usually used to develop mobile alarm clock, and it is a global timer that can start other components (including activity, service and broadcastreceiver) at a specified time or cycle
Get AlarmManager object:
getSystemService(Service.ALARM_SERVICE)
Call one of the ways to set the timer to start the specified component:
Set (int type, long triggerattime, pendingintent operation) sets the triggerattime time to start the component specified by the operation parameter.
"The first parameter specifies the type of timing service. Its value can make: elapsed_realtime: specifies to start the corresponding components of operation after a certain time from now. Elapsed_realtime_wakeup: specifies to start the components of operation formation after a certain time from the actual start time. Even if the system is shut down, the corresponding components of operation will be executed. RTC: Specifies that when Rtc_wakeup: Specifies that the component corresponding to the operation will be started when the return value of the system. Currenttimemills() method is equal to the triggerattime. Rtc_wakeup: Specifies that the component corresponding to the operation will be started when the return value of the system. Currenttimemills() method is equal to the triggerattime. Even if the system is shut down, the component corresponding to the operation will be executed. "
Setinexactrepeating (int type, long triggerattime, long interval, pending intent operation): set an imprecise periodic task.
Setrepeating (int type, pending intent operation): set a periodic scheduled task.
Cancel (pending integer operation) cancels the alarmmanger timing service
Example:
Core code:
Layout:
The above is the whole content of this article. I hope it will help you learn Android Software Programming.