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.

13 comments:

julius said...

Thanks for this tip!

Todd said...

Thanks, it's really a good tip for me. It works fine on emulator.

Jorge said...

well we can use keepScreenOn property inside the layout...

android:keepScreenOn="true"

by example
< RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/frame" android:keepScreenOn="true" / >


Happy Codig!
Jorgesys

www.reforma.com

Khanh said...

Thank you!

Jason Tomlinson said...

Thanks for the xml tip Jorge!

fdfblog said...

Great Tip!!

fdfblog said...

Great Tip!!

bramp said...

thanks!

cruz3r64 said...

great! thanks a lot!

Skilly said...

Thanks!

Michele said...

Thanks!

Grant said...

You rule! Exactly what I was looking for.

Amol Chavan said...

thnks