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