Android Question Send GPS location even when the app is minimized!

Dianzoa

Active Member
Licensed User
Hello Friends!

The tittle resume it all. I try in the debugger to catch location every 30 seconds and it works while the app is in top, but does not work when the app is minimized or the phone is inactive, any tips to catch the location in those cases? The event location changed only get called when the app is active. I need to track the location like every 1 or 3 minutes, even if the app is minimized.

Thanks, Diego.
 

Peter Simpson

Expert
Licensed User
Longtime User
Search the forum for Foreground Service
 
Upvote 0

Dianzoa

Active Member
Licensed User
To be honest I never found a real solution for this issue. I try to send GPS location every 60 seconds and update a database but when the app is minimized I can not call any jobs to do the database update. I think is not really posible to do such things when the app is not active.
 
Upvote 0

Dianzoa

Active Member
Licensed User
I manage it to work, but only works when the phone is charging, if the phone is not charging, after few minutes or secs the foreground service stops execution, I think I already read this same problem on some other post, but no one really could make a solution example. Android claims that it works like I want using foreground services, but I think it's maybe a bug in the B4A implementation of this scenarios? The foregroundservice just die, even the starter service, and we can't do nothing about it , at least in B4A. :(
 
Upvote 0

Dianzoa

Active Member
Licensed User
UPGRADE INFO
If I resume the app, and the foregroundservice starts again, it works for almost an hour now. So, when used for the first time only works for about 3-5 minutes. I will try more things after some sleep.
 
Last edited:
Upvote 0

Dianzoa

Active Member
Licensed User
I have the service run for 12hs now, and works great, my only problem now is that only works like this when I resume the app, and not the first time it opens. The first time the service just works like 5 minutes in the background, and get killed, then I resume the app again, and the service runs forever. Weird.
 
Upvote 0

hatzisn

Expert
Licensed User
Longtime User
Two suggestions:

A) Go to the Settings>Applications and set your app to be excluded from the power settings
B) Use StartServiceAt in End of service start sub to start again the service every a given amount of hours f.e.4 (always foreground with partial lock). On start check the starting intent and do your stuff accordingly.
 
Last edited:
Upvote 0
Top