简体   繁体   English

WakeLock在现代Android中的用途?

[英]Purpose of WakeLock in modern Android?

I'm having a hard time understanding the purpose of WakeLock in modern versions of Android, after the introduction of Doze and Foreground Services. 在引入Doze和Foreground Services之后,我很难理解WakeLock在现代版本的Android中的用途。

It appears as if WakeLocks are pretty much legacy as this point (although not marked as deprecated), replaced by Foreground Services (as WakeLocks are not actually respected by Doze ). 它看起来好像WakeLocks是非常传统的,因为这一点(虽然没有标记为不建议使用),通过前景替换服务(如WakeLocks实际上并不是由尊重打盹 )。

From the documentation : "One legitimate case for using a wake lock might be a background service that needs to grab a wake lock to keep the CPU running to do work while the screen is off" - But this isn't really true anymore after the introduction of doze and foreground services, is it? 来自文档 :“使用唤醒锁的一种合理情况可能是后台服务,它需要获取唤醒锁以在屏幕关闭时保持CPU的正常运行以进行工作” –但是,在关闭后,这种情况就不再成立了介绍打of睡和前台服务,是吗?

Is there still a legitimate use case for using WakeLocks (instead of eg a foreground service)? 还有使用WakeLocks的合法用例(而不是例如前台服务)吗?

Foreground services still don't keep the CPU awake - for that you still need a wakelock. 前景服务仍然不能使CPU保持唤醒状态-为此,您仍然需要唤醒锁。 Cases like ongoing media playback would need both a foreground service (to keep the process alive and to allow wakelocks while the rest of the system is dozing) and a wakelock itself (to keep the actually media playback happening). 诸如正在进行的媒体播放之类的情况,既需要前台服务(以保持进程运行并在系统其余部分处于休眠状态时允许唤醒锁),也需要唤醒锁本身(以保持实际的媒体播放发生)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM