June 12, 2011

How to Prevent Screen Lock in Android while Running Application


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