Refrain your device from sleeping

How to refrain your device from sleeping with App Inventor

Note: with the extension feature, this workaround is now obsolete. Thank you MIT!
Now you can use my Tools Extension and its KeepScreenOn method instead.

As we know, after a certain time the Android device goes inactive. And if the device is sleeping, for example a countdown ends without alarm ... There is no perfect solution with App Inventor to refrain the device from sleeping, because all solutions will drain the battery of your device! Please use these workarounds wisely!

There are the following possibilities:

Include a videoplayer component width x height = 1x1, the videoplayer component must be visible on the screen. Upload a small dummy video. Start the video. In the video completed event start it again (or under some condition desired). By playing the video the application is running without sleep. It fades out the screen, then black, but the application still is running.

This does not work for all components, but it works fine with the Player component.

Thank you for the car alarm sound.
You might be interested in the simplified countdown example for App Inventor 2 provided by richard.

For questions about App Inventor,
please ask in the App Inventor community.Thank you.


App Inventor blocks

These are the blocks used for the "wake lock"

Further blocks used


Tested successfully on Nexus 5 running Android 5.1.


Developing and maintaining snippets, tutorials and extensions for App Inventor takes a lot of time.
I hope it saved some of your time. If yes, then you might consider to donate a small amount!

Donation amount:

or donate some mBTC to Bitcoin Address:

Thank you! Taifun

Download aia file for App Inventor

Back to top of page ...

Creative Commons License
This work by Pura Vida Apps is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License
with attribution (name=Pura Vida Apps and link to the source site) required.

Home | Snippets | Tutorials | Extensions | Links | Search | Privacy Policy | Contact