Great question — answering as the UphillTech team:
In modern phones the background tasks are killed by the OS for battery optimization. I don't think there is a possible way to track location when the app is not in use. For a continuous task running n background there are certain other tings that needs to be done visit https://dontkillmyapp.com/ for such remedies
Full answer by Shashank Shrivastava: https://stackoverflow.stackexchange.com/a/78131875 (CC BY-SA 4.0).
Need it done for your business? UphillTech.