1

I saw a great speech from Commonsware's Mark about multithreading and using wakeful services yesterday at AppsWorld London. He recommends using WakefulIntentService or WakeFulBroadcastReceiver in some situations to ensure your app will be able to continue some long processing and prevent the device to go to sleep.

I have an app that does some background processing regularly when the device screen is off. I use AlarmManager to have it get the stuff done regularly. Since I have a large user base (200.000 active users), I get to see all kind of weird cases when users send me some logfile. Among others I could see that on some devices after the alarm will be triggered, the app starts doing his job and then suddenly just doesn't do anything for many seconds, or even minutes (no entry in the logfile for a while). I assume this is because the phone goes to sleep. What bugs me is that this happens only on some devices, for instance it would happen a lot on Samsung SGS2+, but not on SGS2, SGS3 or SGS4.

So what I'm wondering is: what is the policy to decide when to put the phone to sleep? Is it Android deciding or is it lower at the Linux level? How much tweaking from the manufacturer is allowed? Shouldn't the sleep policy be part of the Android Compatibility definition? Extra question: Are there some levels of being asleep, like several levels of CPU speed, or is it just boolean sleeping / not sleeping?

4

1 回答 1

4

决定何时让手机进入睡眠状态的政策是什么?

一般来说,如果没有任何东西持有 a WakeLock,则设备可以自由地进入“机会挂起”模式,此时 CPU 停止执行指令。

是 Android 决定还是在 Linux 级别较低?

Linux 内核——最初是通过 Android 扩展,现在被整合到股票内核中——处理机会挂起。Userland 应用程序,如 SDK 应用程序,可用于WakeLock阻止机会性挂起。

至于如何根据机会挂起配置内核,我不知道。

睡眠策略不应该是 Android 兼容性定义的一部分吗?

许多好的问题会根据专家的经验产生一定程度的意见,但这个问题的答案往往几乎完全基于意见,而不是事实、参考资料或特定的专业知识。

是否有某种程度的睡眠,比如几个级别的 CPU 速度,或者只是布尔睡眠/不睡眠?

从 Android SDK 应用程序的角度来看,就 CPU 而言,现在与 Intel SpeedStep 风格的 CPU 频率变化相比,它是“布尔睡眠/非睡眠”。某些多核 CPU 可能会打开和关闭内核以节省电量,但​​这通常与机会挂起无关。

于 2013-10-24T18:24:07.777 回答