Android英文文档翻译系列(1)——AlarmManager
原文:个人翻译,水平有限,欢迎看官指正。
public class
AlarmManagerextends Object
Class OverviewThis 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, 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.
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
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将更简单和高效。 You do not instantiate this class directly; instead, retrieve it through 你不需要实例化它的对象,只需要通过Context.getSystemService(Context.ALARM_SERVICE)获取。
英文太菜了,意识还是很模糊,需要加强英语啊,多多阅读英文文档。
当设备在休眠中,注册的闹钟将会保留(如果时间到了将会看情况唤醒设备),但是如果闹钟关掉了 或者闹钟重启了讲会清除前面的设定。
Alarm Manager 将保持CPU激活状态到闹钟广播的接收者的onReceive() 方法运行。
这将可以保证手机不会休眠除非你终结广播事件的处理。
onReceive()返回一次,Alarm Manager就会释放唤醒锁。
这就意味着你的手机在某种情况下一沉睡,你的 onReceive() 方法将结束,
如果闹钟广播的接收者,调用了
Context.startService() ,你的手机将可能在请求的服务运行之前 就睡死。 为了防止上述情况的发生,你的广播接收器和服务需要实现独立的设备唤醒机制,确保你的手机可以 继续运行除非服务已经生效。
Alarm Manager是为了应用在这中情况下的,当你需要让你的程序在某个特定的时间执行,甚 至你的程序并没有运行的时候。
|