I start an activity in my class Locator.java which starts a locacionListener Service. That activity writes positions to a database. I wonder if when i move to next screens(activities), positions will keep writing to the database, or I would need to go back to Locator.java to keep writting. The same when I minimize the application.
I have thouhgt about using a Service, but I want to be sure I need it.
Other scenary, imagine that I only need the position when I am in one activity. I wonder if in that case a service will improve the performance, as if the GPS module stops between activities, I would need to restart it next time I go back to the activity. I that case a service will keep the开发者_开发知识库 module active and next time I go back to the activity it will be quicker to get the position.
I really appreciate your help.
Thanks, David.
In your case you should stop fetching latitude and longitude for location manager when activity destroy and pause using this code.` mLocManager.removeUpdates(this); here mLocationManger is the ovject of LocationManager. and initialize locationlistner loject in onCreate or onResume and call licationUpdate Mathod because you want to update location when you back to activity. I hope this is help.
I have implementeed a service when I need to keep doing a task with the Location. But if I want to use the Location in one Activity I will use the tip from DynamicMind. Whereas to keep working with the Location Service when I am in others activities I need a service.
精彩评论