How to prevent the screen of an android device to turn off during the execution of an Activity?

后端 未结 6 716
我在风中等你
我在风中等你 2020-12-14 15:32

I have an Activity that usually needs some time to watch the screen without interacting with it.

The problem is that the screen turns off, just like wit

6条回答
  •  生来不讨喜
    2020-12-14 16:02

    Add android:keepScreenOn="true" to some widget in your layout XML resource for this activity. So long as that widget is visible on the screen, the screen will not turn off automatically.

    EDIT:

    A WakeLock, as suggested by other answers, technically will work. But then you have to manually release the WakeLock (if you mess that up, the screen will stay on a long time). And, since you could mess it up, you need the WAKE_LOCK permission. Using keepScreenOn avoids all of that.

提交回复
热议问题