当前位置: 代码迷 >> Android >> 通译 android.app.AlarmManager 类
  详细解决方案

通译 android.app.AlarmManager 类

热度:478   发布时间:2016-05-01 16:50:04.0
翻译 android.app.AlarmManager 类

<!-- @page { margin: 0.79in } P { margin-bottom: 0.08in } H1 { margin-bottom: 0.08in } H1.western { font-family: "Times New Roman", serif } H1.cjk { font-family: "DejaVu Sans" } H1.ctl { font-family: "Lohit Hindi" } TD P { margin-bottom: 0in } H2 { margin-bottom: 0.08in } H2.ctl { font-family: "Lohit Hindi" } TH P { margin-bottom: 0in } A:link { so-language: zxx } CODE.cjk { font-family: "DejaVu Sans", monospace } -->

publicclass

AlarmManager

extends?Object

java.lang.Object

????

android.app.AlarmManager


类概括

Class Overview

?

本类提供了许可连接系统警服务。这里允许你预定你的应用程序在未来的某个点运行。当警报响起,已经注册到系统监听的Intent自动启动目标应用程序如果这个应用没有准备运行。在设备睡眠时已经注册的警报被保存(如果在此期间响起则能够执行唤醒设备操作),但是如果设备关闭或重启则警报将被清除。

This class provides access to the system alarm services. These allow you to schedule your application to be run at some point in the future. When an alarm goes off, the?Intent?that had been registered for it is broadcast by the system, automatically starting the target application if it is not already running. Registered alarms are retained while the device is asleep (and can optionally wake the device up if they go off during that time), but will be cleared if it is turned off and rebooted.

?

这个警报管理只要在警报接收者的onReceive()方法中执行就可获得一个CPU唤醒锁。这将保证电话直到你结束掌握的这个广播不会休眠。一旦OnReceive()返回,这个警报管理就释放这个唤醒锁。这意味着电话在你的onReceive()方法完成后就会在一些情况下休眠。如果你的警报监听者调用Context.startService(),电话在请求服务被执行前将会休眠的情况是可能发生的。为了预防这中情况发生,你的BroadcastReceiverService将需要执行一个分开的唤醒锁策略以确保电话在服务成为可用前继续运行。

The Alarm Manager holds a CPU wake lock as long as the alarm receiver's onReceive() method is executing. This guarantees that the phone will not sleep until you have finished handling the broadcast. Once onReceive() returns, the Alarm Manager releases this wake lock. This means that the phone will in some cases sleep as soon as your onReceive() method completes. If your alarm receiver called?Context.startService(), it is possible that the phone will sleep before the requested service is launched. To prevent this, your BroadcastReceiver and Service will need to implement a separate wake lock policy to ensure that the phone continues running until the service becomes available.

?

注意:这个警报管理是预期这种情况当你要运行你的应用程序代码在一个特殊的时候,即使你的应用程序不是当前运行的。进行常规定时操作(响铃,超时设定,等)这是更简单和更多更高效的用法。

Note: The Alarm Manager is intended for cases where you want to have your application code run at a specific time, even if your application is not currently running. For normal timing operations (ticks, timeouts, etc) it is easier and much more efficient to use?Handler.

?

你不能直接实例这个类;要通过Context.getSystemService(Context.ALARM_SERVICE)替换,取回他

You do not instantiate this class directly; instead, retrieve it through?Context.getSystemService(Context.ALARM_SERVICE).

?

Summary

Constants

int

ELAPSED_REALTIME

警报时在SystemClock.elapsedRealtime()(时间来自boot,包括休眠)

Alarm time in?SystemClock.elapsedRealtime()?(time since boot, including sleep).

?

int

ELAPSED_REALTIME_WAKEUP

警报时在SystemClock.elapsedRealtime()(时间来自boot,包括休眠),当警报发生将唤醒设备。

Alarm time in?SystemClock.elapsedRealtime()?(time since boot, including sleep), which will wake up the device when it goes off.

?

long

INTERVAL_DAY

long

INTERVAL_FIFTEEN_MINUTES

通过setInexactRepeating(int, long, long, PendingIntent)有效的不精确的重复间隔被认可

Available inexact recurrence intervals recognized by?setInexactRepeating(int, long, long, PendingIntent)

long

INTERVAL_HALF_DAY

long

INTERVAL_HALF_HOUR

long

INTERVAL_HOUR

int

RTC

警报时在System.currentTimeMillis()(UTC隔开时钟)

Alarm time in?System.currentTimeMillis()?(wall clock time in UTC).

?

int

RTC_WAKEUP

警报时在System.currentTimeMillis()(UTC隔开时钟),当警报发生将唤醒设备。

Alarm time in?System.currentTimeMillis()?(wall clock time in UTC), which will wake up the device when it goes off.

Public Methods

void

cancel(PendingIntent?operation)

移除任何匹配Intent的警报。

Remove any alarms with a matching?Intent.

?

void

set(int type, long triggerAtTime,?PendingIntent?operation)

预定一个警报。

Schedule an alarm.

?

?

void

setInexactRepeating(int type, long triggerAtTime, long interval,?PendingIntent?operation)

设定一个重复警报带有不精确的触发时间要件;例如,一个警报是每小时重复,但不一定在每个小时的开始重复。

Schedule a repeating alarm that has inexact trigger time requirements; for example, an alarm that repeats every hour, but not necessarily at the top of every hour.

?

void

setRepeating(int type, long triggerAtTime, long interval,?PendingIntent?operation)

预定一个重复警报。

Schedule a repeating alarm.

?

void

setTime(long millis)

设置系统隔开时间。

Set the system wall clock time.

?

void

setTimeZone(String?timeZone)

设置系统默认时区。

Set the system default time zone.

?

  相关解决方案