10

I'd like to disable screen saver while my appliction is running. How it can be done? Where is the best place to disable / enable the screen saver? in the first activity? in the application.java?

THelper
  • 15,333
  • 6
  • 64
  • 104
eyal
  • 2,379
  • 7
  • 40
  • 54

2 Answers2

19

The wake lock permission must be specified in the manifest.

<uses-permission android:name="android.permission.WAKE_LOCK" />

Then in the activity use the following to keep the screen on while the activity is running.

getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);

Remember that unnecessarily keeping the screen on unnecessarily drains power from the user's device.

Programmer Bruce
  • 64,977
  • 7
  • 99
  • 97
  • Any idea if this prevents the Google TV screen saver from coming up? – powerj1984 Apr 30 '12 at 13:33
  • 2
    You actually don't need wake lock permission for this window flag, see: https://developer.android.com/training/scheduling/wakelock.html – Mariusz Jun 09 '16 at 14:32
2

You must also add:

import android.view.WindowManager.LayoutParams;