Kim Ras
Kim Ras

Reputation: 972

locationListener is only called once when requested in a Service

I have written a small app, that has a Activity to control and display data, and a Service that Gets data from the GPS and send it to the Activity. Reason for this is that I like this to run even after the Activity is exited..

I did a work around where I in the end of my Location Listener remove the listener and redefined it..

   lm.removeUpdates(locationListener); 
   lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, iGPSMovement, locationListener); 

But It is not nice and now it fails on my HTC desire Z..

Has someoen encountered this? What is the work around?

I have written a small App (One activity) that do not uses a Service and that works fine with the requestLocationChange only called at onCreate..

Please help Kim

Upvotes: 0

Views: 466

Answers (2)

Ben
Ben

Reputation: 21

Not sure this matters anymore, but the reason you had to set your distance to 0 was that this is the MINIMUM distance the unit must move in order for the thread to fire. So if the phone was sitting on your desk and was not moved at least X distance from the spot it occupied when the program began, you would not get an update. By setting it to 0 you are forcing the program to update at your minimum time interval regardless of distance moved. I'm pretty sure it works only as long as both minimum conditions are satisfied. I.e. it's been more than 5 seconds and you've moved more the 10 meters.

Upvotes: 2

Kim Ras
Kim Ras

Reputation: 972

OK so I tried to rewrite a super simple Service and Activity and using a broatcast reciever and that worked like a charme.. So I converts my app and it is still not working... But I then found that the Meters movement HAS to be 0 for the request to work on my Desire.. Is that odd or what? Anyway that solved my issue..

lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, locationListener);

Is what I ended up with and that seams to fix everything regardless of how I communicate to between service and Activity..

Upvotes: 0

Related Questions