What should I replace SCREEN_DIM_WAKE_LOCK with?

user3391426 picture user3391426 · Mar 17, 2014 · Viewed 11.4k times · Source

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");

Answer

user3391426 picture user3391426 · Mar 17, 2014

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.