以下情况:
IntentService
从Activity
开始(因此屏幕打开)。在此过程中,可以发送 1个或许多 intents
(然后IntentService
会依次执行)。这意味着onHandleIntent
可以运行 1次,但也可以运行20次。
在这种情况下,应该在Wakelock
还是acquire
/ release
中将onHandleIntent
和onCreate
中的onDestroy
和Wakelock
中? >
如果在此方法的结尾acquire
是onHandleIntent
中的release
d和intent
d,则设备可以在下一个{{ 1}}开始了吗?
//THIS COULD RUN 20 TIMES IN A ROW
@Override
protected void onHandleIntent(@Nullable Intent intent) {
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
, "WakeLock:");
wakeLock.acquire();
//do a few seconds of blocking work
wakeLock.release();
//can the device fall asleep before the next onHandleIntent?
}