public class Timer extends Object
Applications may need to perform an action at a specified time. Register Intent or
ITimerListener with the timer system. When the registered timer goes off, the system sends the
Intentto the application or calls the listener. Timers will be invalid after the system is powered off
or restarted.
SystemCapability.Miscservices#TIME| 限定符和类型 | 类 | 说明 |
|---|---|---|
static interface |
Timer.ITimerListener |
Provides a callback for a timer.
|
static class |
Timer.OneShotTimer |
Provides the oneshot timer function.
|
static class |
Timer.RepeatTimer |
Provides a repeating timer with a fixed interval for applications.
|
static class |
Timer.TimerIntent |
Creates an
Intent data class to send after a timer is triggered. |
| 限定符和类型 | 字段 | 说明 |
|---|---|---|
static int |
ABILITY_TYPE_COMMON_EVENT |
Indicates that the system sends a
CommonEventData message after the timer
is triggered. |
static int |
ABILITY_TYPE_PAGE |
Indicates that UI component
Ability is started after the timer is triggered. |
static int |
ABILITY_TYPE_SERVICE |
Indicates that background service component
Ability is started after the timer
is triggered. |
static int |
TIMER_TYPE_EXACT |
Describes whether a timer will be delivered precisely at a scheduled time.
|
static int |
TIMER_TYPE_IDLE |
Indicates whether the timer waking up the system is supported in low-power mode.
|
static int |
TIMER_TYPE_REALTIME |
Indicates the timing policy the timer use, which can be REALTIME or UTC.
|
static int |
TIMER_TYPE_WAKEUP |
Describes whether a timer will wake the device up.
|
| 构造器 | 说明 |
|---|---|
Timer() |
public static final int ABILITY_TYPE_COMMON_EVENT
CommonEventData message after the timer
is triggered.ABILITY_TYPE_PAGE,
ABILITY_TYPE_SERVICE,
常量字段值public static final int ABILITY_TYPE_PAGE
Ability is started after the timer is triggered.ABILITY_TYPE_COMMON_EVENT,
ABILITY_TYPE_SERVICE,
常量字段值public static final int ABILITY_TYPE_SERVICE
Ability is started after the timer
is triggered.ABILITY_TYPE_PAGE,
ABILITY_TYPE_COMMON_EVENT,
常量字段值public static final int TIMER_TYPE_EXACT
If the bit flag is set to 1, the timer will be delivered as nearly as possible to the requested
trigger time. However, this may result in high power consumption. An inexact timer will not be delivered
precisely. This is to reduce the impact on device battery use. This type can be used in a combination with
the other two types.
TIMER_TYPE_REALTIME,
TIMER_TYPE_WAKEUP,
TIMER_TYPE_IDLE,
常量字段值public static final int TIMER_TYPE_IDLE
If this bit is 1, the wakeup function is supported in low-power mode.
This can cause heavy power consumption when the device is idle and reduce the battery life.
Therefore, use such timers with caution. You can use them with timers of other types as a combination.
TIMER_TYPE_REALTIME,
TIMER_TYPE_EXACT,
TIMER_TYPE_WAKEUP,
常量字段值public static final int TIMER_TYPE_REALTIME
If the bit flag is set to 1, the timer adopts the REALTIME policy, indicating the time elapsed since
the device boot. If the bit flag is set to 0, the timer adopts the UTC policy, indicating the time
elapsed since 00:00:00 UTC on 1 January 1970. This type can be used in a combination with the other two types.
TIMER_TYPE_WAKEUP,
TIMER_TYPE_EXACT,
TIMER_TYPE_IDLE,
常量字段值public static final int TIMER_TYPE_WAKEUP
If the bit flag is set to 1, this timer wakes the device up when the timer goes off, and the
scheduled action is performed. A non-wakeup timer does not wake the device up, and the scheduled action will
not be performed until the next time the device wakes up. This type can be used in a combination with the
other two types.
TIMER_TYPE_REALTIME,
TIMER_TYPE_EXACT,
TIMER_TYPE_IDLE,
常量字段值