# Prevent sleep in android

**URL:** <https://discourse.processing.org/t/prevent-sleep-in-android/15011>\
**Category:** Processing for Android\
**Created:** [October 29, 2019, 11:55am UTC](https://discourse.processing.org/t/prevent-sleep-in-android/15011 "2019-10-29T11:55:49Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![Waboqueox](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/waboqueox/32/5643_2.png) [@Waboqueox](https://discourse.processing.org/u/Waboqueox)\
**Post date:** [October 31, 2019, 12:51pm UTC](https://discourse.processing.org/t/prevent-sleep-in-android/15011/15 "2019-10-31T12:51:42Z")

</div>

It worked for me just adding this:

Edited: Forgot to take out the protected tag

```auto
    @Override
    void onResume() {
        getWindow().addFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        super.onResume();
    }

    @Override
    void onPause() {
        getWindow().clearFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        super.onPause();
    }

```

[🤦‍♂️🤦‍♂️🤦‍♂️🤦‍♂️🤦‍♂️🤦‍♂️](https://discourse.processing.org/t/evitar-la-atenuacion-del-brillo-al-cabo-de-un-rato-as/13796/3) [🤦‍♂️🤦‍♂️🤦‍♂️🤦‍♂️🤦‍♂️🤦‍♂️🤦‍♂️🤦‍♂️](https://discourse.processing.org/t/prevent-sleep-in-android/15011/3)

---

_[View the full topic](https://discourse.processing.org/t/prevent-sleep-in-android/15011)._
