Monday, March 2, 2009

I want to keep the screen ON

I have seen numerous methods describing how to keep the screen on, all using the PowerManager.WakeLock API. You don't want to access WakeLock too often because it will drain the battery, so why not take the easy approach and let Android do it for you.

Simply call setKeepScreenOn(true) from your View class or any clas that inheriets from View.

Yes I am serious, it is a single line of code to keep the back light on.