服务和唤醒锁定策略 [英] Service and Wake Lock Policy

查看:119
本文介绍了服务和唤醒锁定策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如AlarmManager文档中阐明的:

http://developer.android.com/reference/android/app/AlarmManager.html#RTC_WAKEUP


  

这意味着该手机将在某些情况下,一旦睡作为的onReceive()方法完成。如果你的报警接收机称为Context.startService(),它是可能的手机会睡请求的服务推出之前。以prevent,你的广播接收器和服务将需要实现一个单独的唤醒锁定策略,以确保手机继续运行的直到服务变为可用。


这是我所看到和读到这里:
http://www.androidguys.com/2009/ 12/03 /唤醒与 - 的报警/
https://github.com/commonsguy/cw-advandroid/blob/master/SystemServices/Alarm/src/com/commonsware/android/syssvc/alarm/WakefulIntentService.java

这家伙通过持有到唤醒锁定 服务不仅仅是 直到可用。所以我的问题是,将服务允许,如果它没有唤醒政策运行的该服务的CPU睡觉?


解决方案

  

所以我的问题是,将服务允许,如果它没有通过该服务运行唤醒政策CPU睡觉?


当然。认为睡,当一个关闭其盖(傻默认)的笔记本电脑。有些方法的地方将被中断 - 无论是当前正在运行的应用程序的main()方法。

As stated by the AlarmManager docs:

http://developer.android.com/reference/android/app/AlarmManager.html#RTC_WAKEUP

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.

From what I've seen and read here: http://www.androidguys.com/2009/04/02/wake-up-with-the-alarm/ https://github.com/commonsguy/cw-advandroid/blob/master/SystemServices/Alarm/src/com/commonsware/android/syssvc/alarm/WakefulIntentService.java

That guys holds onto the wake lock through the service not just until it becomes available. So my question is, will a service allow the CPU to sleep if it does not have a wake policy running through the service?

解决方案

So my question is, will a service allow the CPU to sleep if it does not have a wake policy running through the service?

Of course. Think of a laptop that sleeps when one closes its lid (the silly default). Some method somewhere will be interrupted - be it the main() method of the currently running application

这篇关于服务和唤醒锁定策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆