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

后端 未结 6 713
我在风中等你
我在风中等你 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 15:45

    To change it on-the-fly do this:

    if (keepScreenOn)
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    else
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    

提交回复
热议问题