Location sensor does not work with locked screen

Hi guys, I am trying to make a location sensor store its coordinates in tinyDb every 30 seconds.. I have also set up a timer - when the timer starts run, location sensor starts its work! Everything works fine, but if I turn off (or lock) the screen, the sensor stops sending anything - but the timer still works as expected, therefore it is not a background issue, right?
Any idea?

You discovered the LocationSensor stops 'working' when your device 'goes to sleep'. Native App Inventor apps and the LocationSensor/gps do not run in the background . When the device screen goes dark, the LocationSensor component stops reporting geocoordinates; when the device later wakes up, it will continue to report location changes.

You have two options to keep the LocationSensor and your device active:

  • Keep your app alive using a StayAwake routine or an extension by e either using a Stay Awake block routine using a Notifier How to keep the screen on

or you use Taifun’s Tools Extension: https://puravidaapps.com/tools.php

Be aware using either an extension or a block routine drains your device battery rapidly . These work around methods are not running the app in the Background, they force the app screen to stay open.


  • Use an extension like Location Service Extension. This extension is able to run in the background while your app is closed and stores location data (latitude, longitude and optionally current datetime, altitude, accuracy, speed, current address and provider) in TinyDB. . This is a paid extension.

Using the Location Sensor explains some things.

OK, but if that's the case, then why the timer still works normally, even if the screen is locked?

The Clock component documentation ( Clock ) explains why the timer 'still works normally' when the screen is 'locked'.

TimerAlwaysFires Will fire even when application is not showing on the screen if true

You asked about the LocationSensor. Its behavior is discussed LocationSensor . It only works in the foreground. It has been that way for at least eight years

To help you understand how App Inventor works, here are some resources to help you learn to use the AI2 tools. A very good way to learn App Inventor is to read the free Inventor's Manual here in the AI2 free online eBook http://www.appinventor.org/book2 ... the links are at the bottom of the Web page. The book 'teaches' users how to program with AI2 blocks.

There is a free programming course here http://www.appinventor.org/content/CourseInABox/Intro and the aia files for the projects in the book are here: http://www.appinventor.org/bookFiles

How to do a lot of basic things with App Inventor are described here: http://www.appinventor.org/content/howDoYou/eventHandling .

Also look here http://kio4.com/appinventor/index.htm and here http://www.imagnity.com/tutorial-index/ for more tutorials.

Learn about components http://ai2.appinventor.mit.edu/reference/components/
and visit the Library http://appinventor.mit.edu/explore/library Help>Library on the MENU