Tuesday, June 28, 2011

Preventing Screen to Lock while Application is running in Android / Hiding Screen Lock while app running

To prevent lock while running the application can be done two ways.
->PowerManager
->WindowManager
Using Power Manager is not a good way. They easily drain battery. So using Window Manager we can avoid the screen locking while application is running. Add the below snippet in your activity to avoid screen lock :
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

No permissions required. Put the above code in the activity.

No comments:

Post a Comment