I'm new to Android programming and I have been try...
# android
a
I'm new to Android programming and I have been trying to decide on the best approach for polling a device for long/lat. Originally, I was going to have this in a background service, but having read that you can only really poll once in a 15 minute time-frame I have since abandoned that. I have read that AlarmManager can be used however, I feel like this to, isn't suitable. I have been looking into Foreground Services and they seem OK - however; Whats my best approach if I want to run a task in a foreground service say every 10 seconds? - is a foreground service even the right way to go?
k
WorkManager
could be one of the options for scheduling tasks
a
From memory
WorkManager
is also bounded by the 15 min cap - or am i getting confused
Screenshot from 2019-10-20 11-45-31.png
k
Makes sense to me, otherwise apps would drain battery like crazy
a
Sure it makes sense, but how do usual Location apps work then? say a company like Fitbit who plot your entire day on a map?
k
They probably use wearables to track data and then sync to the app? No clue :)
Did you check this one out yet?
a
Yes, so they recommend taking your service to the foreground - which I have started to look at - However, once in the foreground Im unsure on the best way to orchestrate the repeated task (getting long/lat)
k
I have 0 experience with location APIs though I'm not surprised about these restrictions :)
a
I have also looked at
PeriodicWorkRequestBuilder
- but again this can only perform tasks every 15 mins
k
Even for regular background tasks you can't completely trust OS with execution and timing of these tasks, they can get deferred or even cancelled
Say if your phone enters doze mode tasks are executed only during execution window every now and then
Saves battery big time
a
So how do location based apps get around this then?
I will read into that
k
My coworker actually did a good talk on this stuff a while back

https://www.youtube.com/watch?v=B1V0tYdKxjY

a
OKay cool - will watch that
I think Im going to google around and look at say a foreground service that toasts the time every 10 seocnds - then work back from there
k
Apps have to follow these restrictions, even Google maps from what I can tell
If you ever shared your location in Google maps someone you'll see that you are not getting actual live location if their phone is on standby
It could be deferred by hours
From my experience
a
There has to be a way 😛
k
I doubt stock Android would let you do that
It's bad for battery and not good privacy wise, in your specific case
v
Can't we use push notification to make the app report the location?
a
I mean i could look at streams in Kafka maybe
Or maybe a rest endpoint / webhook design
k
Not sure how that will help you get around the restriction for background task
Not very experienced in that area either though
a
No if we abandoned the background task
k
I'm seeing fused location API being recommend over foreground service for location tracking
👍 1
a
Yes I have an implementation of FusedLocationAPIClient
Ahh i didnt realise it can give bundled location updates in intervals - this could be good