public static class Timer.OneShotTimer extends Object
There are two types of oneshot timers. The difference lies in the action after a oneshot timer goes off.
The system sends an Intent object to an application, or invokes
the ITimerListener callback.
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
static Timer.OneShotTimer |
getTimer(Context context,
Timer.ITimerListener listener) |
Obtains a oneshot timer.
|
static Timer.OneShotTimer |
getTimer(Context context,
Timer.TimerIntent operation) |
Obtains a oneshot timer object.
|
void |
start(int type,
long triggerTime) |
Starts a timer.
|
void |
stop() |
Cancels the timer.
|
public static Timer.OneShotTimer getTimer(Context context, Timer.TimerIntent operation)
When the timer goes off, the system sends an intent to start a component.
context - Indicates the application context.operation - Indicates the intent to send when the timer goes off.OneShotTimer instance that is created using the operation as the key.public static Timer.OneShotTimer getTimer(Context context, Timer.ITimerListener listener)
When the timer goes off, the system calls the ITimerListener interface.
context - Indicates the application context.listener - Indicates a listener to monitor whether the timer goes off.OneShotTimer instance monitored by the listener.public void start(int type,
long triggerTime)
type - Indicates a timer type.triggerTime - Indicates the point in time for triggering the timer, in milliseconds.
The time will be automatically set to 5000 milliseconds after the current time if
the passed value is smaller than the current time plus 5000 milliseconds.Timer.TIMER_TYPE_REALTIME,
Timer.TIMER_TYPE_WAKEUP,
Timer.TIMER_TYPE_EXACTpublic void stop()
The timer to be canceled is related to the second parameter of the following methods:
Note: If a timer is created based on Intent, calling this
method will cancel all timers. If a timer is created based on a listener defined by ITimerListener,
calling this method will cancel all timers monitored by the listener.