I'm writing a simple distance-tracking app in Unity (because I'm much, much more familiar with it than normal Android development environments and the app is intended for personal use), and my problem is that, when the phone is locked or (presumably) the app closed, data is not collected.
The way the app works is that it queries location every few meters, using Unity's Location Service interface, and adds it up to a total distance once the run is finished.
The app is intended to run on Android 9, and it must measure distance precisely for the duration of at least 1-2 hours. Therefore, I need the battery to last at least that long, especially when Bluetooth services, such as music or heart-rate syncing from a watch, are running alongside it.
My experience with Android development is very low; almost nonexistent. I realize I need some sort of background process, but I'm not sure which, and nor which works best with Unity's built-in Location Service API, or Unity in general.
My research so far tells the process should, in fact, be a foreground process, because newer versions of Android restrict background services to querying for location only once every few hours. Further research says I should work with Work Manager, though I'm still not sure if that's correct. Is measuring location every second or so considered deferrable?
Perhaps I should use an IntentService instead? I'm confused.
What is the appropriate and up-to-date service to use for this purpose?