How to keep an app running continually with GPS on?

我的梦境 提交于 2019-12-25 08:03:57

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!