服务,WakeLockWakeLock

2023-09-04 11:18:46 作者:这世道,真心没有比钞票贵

我经历的问题和功放后有点糊涂了;在回答关于#1 WakefulIntentService 。我只是想获得一些知识这一主题,以确保我的理解是正确的,请随时纠正我,如果我错了。

我建了一个小的应用程序,在这里我使用的是背景服务,保持播放音乐时的用户摇动手机。经过笔者测试设备被锁定,屏幕关闭,它按预期工作。

我是从这个论坛,该服务可能会关闭,一旦该设备进入睡眠。真的吗?就我而言,它的工作原理永远,我失去了一些东西?

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

我尝试运行在一个服务,虽然该设备被锁定,屏幕关闭,我的定时器运行pretty的多,我可以一个计时器肯定地说。因为我用得到通知,每当我的定时器之旅。

解决方案   

我是从这个论坛上听到,该服务可能会关闭,一旦该设备进入睡眠。是真的吗?

是的。

  

在我的情况下,它的工作原理总是

那么别的设备上是保持设备从入睡。也许使用 亚行外壳dumpsys功率 看看 WakeLocks 都很优秀。

  

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

所述装置可以入睡如果用户是不活动的,并没有什么保持器件清醒。 A WakeLock 用于确保设备保持清醒。对于事务型的工作(例如,下载文件), WakefulIntentService 结合的 IntentService WakeLock 使保持清醒的设备,只要有必要(和的只有的,只要有必要)相对容易。

WakefulIntentService 不适合与需要无限期地运行,如音乐播放服务的使用。针对这一情况,管理自己的 WakeLock

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.

头条 都是共享经济,为何差别那么大

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.

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?

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

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?

Yes.

In my case, it works always

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.

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

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 is not suitable for use with services that need to run indefinitely, such as a music player. For those, manage your own WakeLock.

 
精彩推荐
图片推荐