Keeping a geolocation service running?
I'm asked to do an app that would r开发者_开发技巧un a geolocation service during some employees working time. I've got a few questions about that:
-Is it possible to have a service running as long as the user doesn't stop it (start/stop button)?. From my understanding a service is bound to an activity, which can be killed anytime by Android...
-What's the best way to do some location tracking in terms of battery life? Is it the same to 1/create, get an update and delete a LocationManager every x seconds and 2/to create once a LocationManager and set the minTime
arg in LocationManager.requestLocationUpdates to x?
Thanks
1) Yes it is possible to keep a service running for as long as the user (or in times of a resource crunch, the system) does not kill it. A service that has to run this way should override the
onStartCommand()
method and be started via
Context.startService()
What you are referring to are services that override onBind() and are started via
context.bindService()
Read the Service documentation, it contains a description of the lifecycles of both kinds of services.
2) One of the best guides for best practices for geo-location is written here by Reto Meier. Check it out
精彩评论