GPS location & time tracking in background / when screen is not active

Hi,

I am currently working on a GPS tracking app but I am facing problems that the GPS/Tracking would always stop once the screen turns of or you leave the app for a short moment (e.g. to reply to a text message)… I need the GPS to continue and also a time tracker to stay alive when the app is in background for a short time or screen turns off…

It seems that there is currently no way to completely run the app in background, even tough MIT is working on Tasks to run services in the background… But unfortunately it is beta for now and their beta version does not have any MAP component (idk why because it HAS a location sensor which can even run in Task)

But IS THERE A SOLUTION to at least make the GPS continue while the screen turns of or the app is left for a short period of time?? Because if there is absolutely no way, I think I’ll have to stop working on this project because who wants a route tracker that always has to stay opened and screen kept active…

I found this Let your app run its background service(s) and would like to give it a try but can any of the developers here tell me if this could really work and does it negatively affect the app / phone?

@thunkable are you also working on Tasks/Background Services or will you implement this in future updates like MIT will?

best, Chris

1 Like

What I don’t understand: if Apps cannot work in background why can the
Proximity Sensor continue working in background?

And in case there is no way to track gps / time in background - is there an extension/way to deactivate the screen when the proximity sensor detects close object (like putting phone into my pocket and it keeps running but screen does not respond to touch events)?

I’m the author of Let your app run its background service(s). I’ve just developed a app with a GPS tracking function using URI of Baidu Map. To the most of my knowledge, it just works out to be fine on most devices(keep tracking for more than 1h until the usr closes it). U can just have a try and please remember to leave a comment with your result. : )

best
Pzoom

3 Likes

So, it is not possible to run the application in the background 24 hours?
I created an application and would like to leave it running 24 hours, the application saves the location of the map in a database where I can query to crawl.

no unfortunately you can’t… I also tried Pzooms method but it did not work for me… The app always stopped GPS and tracking once it was not active on screen… You could try using the service beta version of MIT app inventor but unfortunately they do not include any map element so far therefor it is quite useless for me right now…

1 Like

sad, now that my application was almost ready :frowning:

Are you researching other alternatives?

unfortunately for now I haven’t found any solution to this… That’s why I also stopped working on my tracking project (should become a tracker for walking the dog).

An idea that I had is if there might be a possibility to combine the Location sensor task from http://services.appinventor.mit.edu with the map and other elements from thunkable… But I am no developer so I don’t know if there is any chance of combining the main app from thunkable with the background services from the MIT Beta e.g. in Android studio…

Any devs here that can answer if it could be possible to combine the two .apks? Maybe it would also be possible to create a tool similar to Project Merger Tool: combine two Thunkable projects into one but enabling to combine tasks from MIT AI2 and Screens from Thunkable?

Is there no other application that lets my application stay in the background?
I’m just going to track my own vehicle.

The notification extension has a block to move the app to the background :smile:

Yeah it puts the app into background with pausing it. Still the app cannot continue to run in background!

1 Like

Hey guys

I use the clock timer instead of LocationChanged in my app and set the LocationSensor.ProvierName to “gps” (as a textblock). My app is still running in the back even if I open another app or the screen is turned off.

Hope this helps

1 Like

@Dennis, can you show me?

the blocks that I use are these.

Unbenannt

Like I said you can use the clock instead of “When Google Maps.OnLocation Changed”.

For my purpose the clock fires every 5 seconds and you can implement an additional check if the latitude or longitude has changed.

I tried it on my HTC U11 Life with Stock Android 8.0.0 and it does not work. GPS will always stop once the app is out of focus!

1 Like

I don’t know what your blocks are. I use this to check if I am near a certain point and it works even when the screen is turned off. I don’t know if you can store values in firebase with this method but if not I’m sure you can make a workaround.

Edit: I thought it does not work because the GPS icon disappeared when leaving the app but it seems to work but only partly…

The Blocks I’ve used:

The small test app that I created adds a marker every 2 seconds at the current position and adds time and coordinates to a list.

I tried locking the screen, working in other apps and continuing using the test app. It seems to work, however there are parts missing:

When I locked the screen the app seems to be much less responsive… There are bigger time differences like 13 instead of 2 seconds… Not sure if the system is doing this to save battery or why this is happening…

I could not yet try it for a longer period of time but I think the apps process might also get killed by the system after some time… So it basically somewhat works but it does not seem a smooth solution… Also I am really wondering why the GPS icon disappears when leaving the app while it still receives GPS data…

Okay - tried it for a little longer now. It does not work. At least if you have one of the later Android versions, the app is being killed after some time inactivity… No way you could use this for production / professional apps :grimacing::see_no_evil:

I liked it, for my situation that is simple, at the moment answered.

Thank you

well if you do not build an app you want to publish and it works for your device and (current) Android version it is a nice workaround. But for any App that should be published in the Playstore or shared with other people you cannot use this :wink:

The solution of clock and location provider name -gps works very good tested on galaxy s6 android 7 and nexus p6 android 8 thank you all for the nice simple solution
Tal.