- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我是 WakeLock 概念的新手,需要您的帮助。
问题:
我假设 WakeLock 是某种类型的锁,当执行代码持有它时会阻止设备休眠。如果设备已经处于 sleep /待机模式,代码会执行吗?假设它永远不会获得唤醒锁?
当一个长时间运行的任务(大约 7-8 秒)在后台线程 (AsyncTask) 中完成时,我是否应该为保持唤醒锁而烦恼? AsyncTask 是否已经为我获取了它?
欢迎链接到官方文档和关于唤醒锁的文章。
谢谢。
最佳答案
1.如果手机处于完全 sleep 模式,除了来电,您可以使用 AlarmManager Intent 唤醒手机。
来自AlarmManager类文档:
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.
2.如果您使用的是 AsyncTask ,您将希望将结果发布到 onPostExecute()
上的 UI 线程上
来自AsyncTask文档:
AsyncTask enables proper and easy use of the UI thread. This class allows to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers.
3.建议你看一下Power Manager的官方文档这很好地介绍了 WakeLock 概念。
关于android - 初学者问题: Wakelocks,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4252434/
我的应用程序使用需要互联网连接才能在后台运行的服务。但是,当 android 进入休眠状态时,我的服务无法再访问互联网。我已经看到 wakelock 可以修复它,但它似乎只是保持网络正常运行就有点矫枉
我有一个应用程序需要连续使用 WiFi 和加速度传感器来收集数据,因此我需要使用 WakeLock 方法来保持这些传感器处于 Activity 状态。但现在我遇到了手机运行几个小时后有时会随机重启的问
我的应用程序有一项服务,基本上可以解析 X 数量的 RSS 提要。大多数提要都相当小,但有些提要的大小可能在 1MB 左右。我在服务的 AsyncTask 中解析它们。解析可能相当耗时,具体取决于用户
我是 WakeLock 概念的新手,需要您的帮助。 问题: 我假设 WakeLock 是某种类型的锁,当执行代码持有它时会阻止设备休眠。如果设备已经处于 sleep /待机模式,代码会执行吗?假设它永
Tag name should use a unique prefix followed by a colon (found tag). For instance myapp:mywakelockta
免责声明:我的应用已经在没有任何唤醒锁的情况下运行了 1 年多,并且对于大多数设备来说一切都很好。 我正在跟踪 GPS,它的工作原理如下: AlarmReceiver 每 5/10/15 分钟启动一次
pm 和 keepScreenOn 变量是全局定义的。 我在 OnCreate 方法中获取 PowerManager.WakeLock: pm = (PowerManager) getSystemSe
我开发了一个名为 Multi Countdown Timer 的 Android 应用程序,我们可以在其中同时启动多个计时器。该应用程序使用前台服务在后台运行,以便持续运行并覆盖 Android 的
我有一个信号让我的应用休眠指定的分钟数(使用 AlarmManager),然后再将其唤醒。 一切正常,只是屏幕永远不会亮起。我正在使用 BroadcastReceiver 类中的唤醒锁: K
在 cat/proc/wakelocks 之后我得到了这样的东西。但是列中的数字是什么意思? ------ KERNEL WAKELOCKS (/proc/wakelocks) ------
我目前正在开发一个不时运行服务的应用程序。目前,该服务获取一个唤醒锁,读取一些传感器并通过 WIFI(如果有)发送一些信息。现在我想知道唤醒锁是否会影响传感器和连接性。是否可以在没有任何唤醒锁的情况下
我有一个按钮,当您单击它时,它会打开唤醒锁,而且效果很好!但是,当您再次单击它时,它应该会关闭 WakeLock,但它只会让应用程序崩溃!任何帮助将不胜感激,我知道这不是因为我正在更改图像,因为那部分
我只是想知道我这样做是否正确;我正在编写一个通知应用程序,它可以在手机休眠时显示通知 禁用键盘锁 获取唤醒锁 显示通知 设置超时警报并重新启用键盘锁并在用户不触摸屏幕时释放唤醒锁。4.1 用户触摸屏幕
我有一个 BroadcastReceiver,它在发送 SMS 后监听“SMS_SENT”Intent。据我所知,SMSManager 确实提供了一个唤醒锁,以便它可以实际发送 SMS(我没有这方面的
我正在使用 WatchFace API(扩展 CanvasWatchFaceService)为 Android Wear 开发一个表盘。 我使用了 here 中的代码构建一个每秒运行代码的自动收报机。
我正在向 Android 应用添加通知,目前只有模拟器可以测试。收到通知后,将调用 GCMBaseIntentService 子类 (GCMIntentService) 中的 onMessage()
我已经阅读了在这里找到的关于 WakeLock 的各种解决方案,例如在 AndroidManifest.xml 中添加 Permission 以及确保将 GCMIntentService 的 Cons
我想在我的 Activity 中使用警报管理器。我像这样在主要 Activity 的 onPause 方法上设置了一个警报, Intent intent= new Intent(namaz_vakti
我需要在 Android 手机上进行后台 GPS 跟踪,目前我计划有两种情况: 当手机连接到(汽车)充电器时,获取频繁的 GPS 位置(每分钟)。 当手机未连接充电器时,仅每 5-30 分钟轮询一次位
我有一个 MediaPlayer 在服务中运行,该服务正在播放来自 URL 的音频(流)。截至目前,它似乎运行良好,甚至在我将手机置于待机状态时继续播放。 我目前没有获得唤醒锁。我的问题是: 在我的情
我是一名优秀的程序员,十分优秀!