I am trying to write an app that tracks location in background and sends data to a server -- to monitor where my family members are, for example.
Currently I am playing with https://github.com/android/location-samples, particularly with LocationUpdatesBackgroundKotlin that seems to be the best way to receive location updates, but
after receiving about 8-10 location updates in background, the gps icon on the status bar dies without anyway notifying the application (here is the android/phone info, but I want the app to be compatible to Android 5.1).
I want to somehow know is receiving location updates alive or not and re-start it if it's dead (restarting receiving updates with fusedLocationClient.requestLocationUpdates
on line 105 of MyLocationManager
helps receiving further updates, but I have to monitor the status by eye).
Is there any way out, or a more reliable approach? Thanks.
P.S. Have been writing for android for a week.
It comes out for Android 5 Lollipop it's better (much more stable) to use third-party library for bacground location receiving, namely io.nlopez.smartlocation.SmartLocation
from 'io.nlopez.smartlocation:library:3.3.3'
, as decribed here, along with a foreground service, as Rudrik Patel mentioned. Works like a charm.