What you should pay attention to in android development-AlarmManager

Source: Internet
Author: User

  1. Public static final int ELAPSED_REALTIME
  2. // When the system is sleep, 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 ).
  3. Public static final int ELAPSED_REALTIME_WAKEUP
  4. // Wake up the system. The usage is the same as ELAPSED_REALTIME. The system value is 2 (0x00000002 ).
  5. Public static final int RTC
  6. // When the system is sleep, 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 ).
  7. Public static final int RTC_WAKEUP
  8. // Wake up the system. The usage is the same as that of RTC. The system value is 0 (0x00000000 ).

    It can be roughly divided into two types: relative time and absolute time.

    Therefore, triggerAtTime settings vary depending on the type used.

    If you use the ELAPSED_REALTIME_WAKEUP type, you should call SystemClock. elapsedRealtime () to obtain the relative time, and add the delay you set.

    Java code
    1. AlarmManager. set (AlarmManager. ELAPSED_REALTIME_WAKEUP, SystemClock. elapsedRealtime () + 5000, sender );

      If you use the RTC_WAKEUP type, you should call System. currentTimeMillis () to obtain the time since January 1, plus the delay you set.

      Java code
      1. AlarmManager. set (AlarmManager. RTC_WAKEUP, System. currentTimeMillis () + 5000, sender );

        ============================

        The setRepeating method has four parameters. The meanings of these parameters are as follows:

        Type: indicates the alert type. Generally, the values are AlarmManager. RTC and AlarmManager. RTC_WAKEUP. If you set the value of type to AlarmManager. RTC indicates a normal timer. If you set the value of type to AlarmManager. in addition to the timer function, RTC_WAKEUP also generates audible alarms (for example, audible alarms and vibrations ).

        TriggerAtTime: the time to wait for 1st running times, that is, the Execution Delay Time, in milliseconds.

        Interval: The execution interval in milliseconds.

        Operation: A PendingIntent object that indicates the operation to be performed after the time. Similar to Intent, PendingIntent can encapsulate Activity, BroadcastReceiver, and Service. However, unlike the Intent, PendingIntent can exist independently of the application.

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.