简体   繁体   中英

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.

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 ).

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?

Is there still a legitimate use case for using WakeLocks (instead of eg a foreground service)?

Foreground services still don't keep the CPU awake - for that you still need a wakelock. 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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