简体   繁体   English

如果将服务放在奥利奥的前台,是否需要设置唤醒锁?

[英]Do I need to set a wakelock if a service is put in the foreground in oreo?

Do I need to set a wakelock if a service is put in the foreground in oreo? 如果将服务放在奥利奥的前台,是否需要设置唤醒锁?

Also, connected to the previous one: 另外,连接到上一个:

The flow is like this, simplified for easier understanding: 流程是这样的,简化了以便于理解:

MainActivity -> ContextCompat.startForegroundService of MyService-Intent -> in MyService: onStartCommand -> thread start -> in Thread: Thread.sleep MainActivity-> MyService-Intent的ContextCompat.startForegroundService->在MyService中:onStartCommand->线程启动->在Thread:Thread.sleep中

Sometimes, wenn Thread.sleep is longer than a certain time, the execution of the thread stops. 有时,如果Thread.sleep的时间超过某个时间,则线程的执行将停止。 Once I activate the phone again, the execution continues. 一旦我再次激活电话,执行将继续。 How to constantly continue it? 如何不断地继续下去呢?

发生这种情况的原因是,当用户在一段时间内不插拔设备并使其静止不动时,设备会进入打do模式,而屏幕关闭时,请参阅此更多详细信息https://developer.android.com/training/monitoring-device-state/doze -standby#understand_app_standby ,一种替代方法是使用工作管理器以获取更多详细信息,请参见https://developer.android.com/topic/libraries/architecture/workmanager/basics

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

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