服务,唤醒锁 [英] Service, WakeLock

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

问题描述

问完问题后我有点困惑 &Stackoverflow 中关于 WakefulIntentService 的答案.我只是想获得一些关于这个主题的知识,以确保我的理解是正确的,如果我错了,请随时纠正我.

I am bit confused after going through the questions & answers in Stackoverflow about WakefulIntentService. I just would like to get some knowledge on this topics to make sure my understanding is correct, please feel free to correct me, if I am wrong.

我构建了一个小应用程序,我在其中使用后台Service,只要用户摇晃手机,它就会继续播放音乐.我在设备锁定和屏幕关闭后进行了测试,它按预期工作.

I built a small application, where I am using a background Service that keeps playing music whenever the user shakes the mobile. I tested after the device is locked and screen is turned off and it works as expected.

  1. 我从这个论坛听到的信息,一旦设备进入睡眠状态,该服务可能会关闭.真的吗?就我而言,它始终有效,我是否遗漏了什么?

  1. What I am hearing from this forum, the service might turn off as soon the device goes to asleep. Is that true? In my case, it works always, Am I missing something?

WakeFulIntentService 需要什么?我们什么时候需要使用WakefulIntentService?

What is the need of WakeFulIntentService? When do we need to use WakefulIntentService?

我尝试在 Service 中运行计时器,尽管设备已锁定且屏幕已关闭并且我的计时器正在运行,但我可以肯定地说.因为我曾经在我的计时器跳闸时收到通知.

I tried running a timer in a Service, though the device is locked and screen is turned off and my timer is running pretty much I can say for sure. Because I used to get notification whenever my timer trips.

推荐答案

我从本论坛了解到,一旦设备进入睡眠状态,该服务可能会关闭.是真的吗?

What I am hearing from this forum, the service might turn off as soon the device goes to asleep. Is that true?

是的.

就我而言,它总是有效

然后,您设备上的其他东西会阻止设备进入睡眠状态.或许可以使用adb shell dumpsys power 来看看WakeLocks 有什么出色的.

Then something else on your device is keeping the device from falling asleep. Perhaps use adb shell dumpsys power to see what WakeLocks are outstanding.

WakeFulIntent 服务需要什么?我们什么时候需要使用 WakefulIntentService?

What is the need of WakeFulIntent Service? When do we need to use WakefulIntentService?

如果用户处于非活动状态并且没有任何东西使设备保持唤醒状态,设备可能会进入睡眠状态.WakeLock 用于确保设备保持唤醒状态.对于事务类型的工作(例如,下载文件),WakefulIntentService 结合了 IntentServiceWakeLock 以使设备保持唤醒状态只要必要的(并且只要有必要)相对容易.

The device may fall asleep if the user is inactive and nothing is keeping the device awake. A WakeLock is used to ensure the device stays awake. For transactional-type work (e.g., downloading a file), WakefulIntentService combines an IntentService and a WakeLock to make keeping the device awake as long as necessary (and only as long as necessary) relatively easy.

WakefulIntentService 不适合与需要无限期运行的服务一起使用,例如音乐播放器.对于这些,请管理您自己的 WakeLock.

WakefulIntentService is not suitable for use with services that need to run indefinitely, such as a music player. For those, manage your own WakeLock.

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

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