Stop Android device from sleeping

I’m trying to develop a very simple application that displays as a slide show with images that I’m sure I don’t understand (if anyone has any tips, it’s very much appreciated), but what they are interested in is to prevent the device from switching to sleep if his left bike is through these images?

+1
source share
3 answers

using

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 

will make a screen on which the lock will be disabled. Remove it using

  getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 
+6
source

Add android:keepScreenOn="true" to some widget in the activity layout XML file. While the action is in the foreground, the device does not fall asleep.

+4
source

Source: https://habr.com/ru/post/1434847/


All Articles