问题
I have an application that is required to log the user's location every couple of seconds, the entire time it is on.
On does not mean in the foreground,or that even the Android's screen is on.
What is the suggested way to accomplish it?
I've heard of background and foreground services, and also saw something about Jobs. I also saw this was possible with a WakeLock.
I am not sure what is the best method of choice.
The need to conserve Battery life is of course an issue.
回答1:
You should use Service, you can choose that the service wil keep running even after your app was closed.
YET if the device is low on resources it might close your service. you can use FOREGROUND service if you want to minimize the chance android will close your service. inside the service use LocationManager / FusedLocation to get the location every X time. you set it up with LocationListener so everytime it set onLocationChanged you upload to firebase.
Useful links:
Make your app loaction aware
Services
来源:https://stackoverflow.com/questions/41407907/how-to-keep-an-app-running-continually-with-gps-on