Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Wakelock and FLAG_KEEP_SCREEN_ON?

Tags:

android

screen

Keeping the screen awake can be accomplished by using a wakelock by

mWakeLock = mPowerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK,                  getClass().getName()); 

Or by adding the FLAG_KEEP_SCREEN_ON to the window,

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 

What is the technical difference between the two and in terms of performance and battery life which is recommended?

like image 215
Ragunath Jawahar Avatar asked Dec 07 '10 13:12

Ragunath Jawahar


Video Answer


2 Answers

A wakelock gives you way more control (Like waking the phone to download something without turning the screen off) and requires your application to hold the wakelock permission.

Therefore FLAG_KEEP_SCREEN_ON is recommended if all you want is to keep the screen on while your window is visible.

like image 84
mibollma Avatar answered Sep 22 '22 12:09

mibollma


Wakelock is vague, since it has many different options. The flag FLAG_KEEP_SCREEN_ON only does that.

| Flag Value              | CPU | Screen | Keyboard | ----------------------------------------------------- | PARTIAL_WAKE_LOCK       | On* | Off    | Off      | | SCREEN_DIM_WAKE_LOCK    | On  | Dim    | Off      | | SCREEN_BRIGHT_WAKE_LOCK | On  | Bright | Off      | | FULL_WAKE_LOCK          | On  | Bright | Bright   | 

Please see wakelock or PowerManager for Android specifics, and other answers for the exact implementation.

like image 27
not2qubit Avatar answered Sep 25 '22 12:09

not2qubit