I am currently utilizing the below referenced code for a wake lock on an alarm notification activity. However, SCREEN_DIM_LOCK
has been depreciated. So, what should I be replacing it with?
//Instance of wake lock for AlarmActivity
PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "MyWakeLock");
Your app acquires a partial wake lock by calling acquire() with the PARTIAL_WAKE_LOCK flag. A partial wake lock becomes stuck if it is held for a long time while your app is running in the background (no part of your app is visible to the user).
Wakelocks. By monitoring the contents of the /sys/power/wake_lock file (root access required), you can see that the PARTIAL_WAKE_LOCK is the only wakelock that stays in effect after the power button is pressed. The other wakelocks keep the display from turning off, with various brightness levels.
Options 1) finish() 2) getGPSStatus() 3) onProviderDisable() 4) getGPS().
Android Developer documentation specifies that SCREEN_DIM_WAKE_LOCK
should be replaced with FLAG_KEEP_SCREEN_ON
. After doing a bit of digging, I turned up this...
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
It should be placed in the onCreate()
method.
It can be replaced for FLAG_KEEP_SCREEN_ON
, as the javadoc says, but this will prevent the screen from dimming - it will remain bright.
This API should not have been deprecated - it is still needed in some cases, such as the "dim" case.
See also this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With