# Android: How to prevent а device from going to sleep?

**URL:** https://forum.castle-engine.io/t/android-how-to-prevent-device-from-going-to-sleep/2133
**Category:** Uncategorized
**Created:** [March 19, 2026, 3:54pm UTC](https://forum.castle-engine.io/t/android-how-to-prevent-device-from-going-to-sleep/2133 "2026-03-19T15:54:35Z")
**Posts on this page:** 1
**Showing post:** 7

<div class="post-metadata">

### Author: ![Recongalina](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/recongalina/32/1530_2.png) [@Recongalina](https://forum.castle-engine.io/u/Recongalina)
#### Post date: [March 27, 2026, 4:35pm UTC](https://forum.castle-engine.io/t/android-how-to-prevent-device-from-going-to-sleep/2133/7 "2026-03-27T16:35:05Z")

</div>

Ok, I made it just a screen hold like for a video player. It doesn’t even require permission.

Here is the service I wrote:

> <https://github.com/SerufuYua/training_timer_2/blob/7de098f64fed898ffec860c30ffbf1aac92a3ab7/android_services/keep_screen/app/src/main/java/io/castleengine/ServiceKeepScreen.java>

Here is Pascal usage:

> <https://github.com/SerufuYua/training_timer_2/blob/7de098f64fed898ffec860c30ffbf1aac92a3ab7/code/seqkeepscreenservice.pas#L46>

According to this documentation:

> **[Keep the screen on  |  Background work  |  Android...](https://developer.android.com/develop/background-work/background-tasks/awake/screen-on)**
>
> Learn how to prevent the device screen from turning off in Android applications using \`FLAG\_KEEP\_SCREEN\_ON\` programmatically or the \`android:keepScreenOn\` XML attribute, while being mindful of battery consumption.

This functionality is already enough to make my app fully usable. And I can make the [release](https://forum.castle-engine.io/t/my-project-training-timer-2-zero-time/2136).

PS: For Windows version added same functionality.

PS2: Background counting isn’t implemented yet, but I thinking on it.

---

_[View the full topic](https://forum.castle-engine.io/t/android-how-to-prevent-device-from-going-to-sleep/2133)._
