java – block screen "wipe" for inactivity

Question:

My app works as a guide for a professional illuminator, it works passively (responds via Bluetooth to user commands in their work tool) or offline where the user can manually operate it in parallel with their tool, the question is that on both occasions the user would spend a long time without interacting with the application, however reading its data constantly, it is essential that the screen does not turn off or darken, I know that the user can very well set this manually, but I wanted to within the application.

I searched on Google but it only appears nonsense, talking about an app to save battery and etc, the problem is that the keywords are the same as several doubts of lay users.

I searched the site but couldn't find anything here.

I looked on Google's Developers, but because I don't know English very well, and because their explanation isn't very intuitive, I didn't get any constructive results. Can someone help me?

Answer:

Try putting this in your Activity 's onCreate

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

Or inside your layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:keepScreenOn="true">

If you want to read more about:

https://developer.android.com/training/scheduling/wakelock.html

I hope it helps!

Scroll to Top