Dayerman
Dayerman

Reputation: 4003

Keep locationListener active between activities or when the app is minimize

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.

Upvotes: 2

Views: 523

Answers (2)

Dayerman
Dayerman

Reputation: 4003

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.

Upvotes: 0

DynamicMind
DynamicMind

Reputation: 4258

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.

Upvotes: 1

Related Questions