acquireWakeLock()方法中获取了 SCREEN_DIM_WAKE_LOCK锁,该锁使 CPU 保持运转,屏幕保持亮度(能够变灰)。这个函数在Activity的 onResume中被调用。releaseWakeLock()方法则是释放该锁。它在Activity的 onPause中被调用。利用Activiy的生命周期,巧妙的让 acquire()和release()成对出现。
Context.getSystemService()
.方法获取PowerManager实例。 PARTIAL_WAKE_LOCK:保持CPU 运转,屏幕和键盘灯有多是关闭的。 html
SCREEN_DIM_WAKE_LOCK:保持CPU 运转,容许保持屏幕显示但有多是灰的,容许关闭键盘灯 java
SCREEN_BRIGHT_WAKE_LOCK:保持CPU 运转,容许保持屏幕高亮显示,容许关闭键盘灯 android
FULL_WAKE_LOCK:保持CPU 运转,保持屏幕高亮显示,键盘灯也保持亮度 ide
ACQUIRE_CAUSES_WAKEUP:Normal wake locks don't actually turn on the illumination. Instead, they cause the illumination to remain on once it turns on (e.g. from user activity). This flag will force the screen and/or keyboard to turn on immediately, when the WakeLock is acquired. A typical use would be for notifications which are important for the user to see immediately. 函数
ON_AFTER_RELEASE:f this flag is set, the user activity timer will be reset when the WakeLock is released, causing the illumination to remain on a bit longer. This can be used to reduce flicker if you are cycling between wake lock conditions. ui