2

I am using a service to track the location of the users device, they are able to toggle the service to begin tracking whenever they wish and they can toggle it off when they are done tracking.

My problem is, onProviderDisabled gets fired when the GPS is disabled, onProviderEnabled doesn't get called when the GPS is enabled again which causes me problems as I need it to switch back over to GPS when it becomes available.

Is this a known issue? Are there any workarounds?

JamieB
  • 923
  • 9
  • 30
  • Which sdk version are you using? I'm using 2.2 and I'm sure onProviderEnabled() gets called okay. – John J Smith Sep 13 '12 at 21:18
  • Is this when using a service? I am using min-8 target-14. – JamieB Sep 14 '12 at 00:21
  • Yes, my LocationListener is called from a service and the device is an HTC Desire. – John J Smith Sep 14 '12 at 18:29
  • 1
    Can you please post your code as well? You might be missing something. – Nicholas Sep 16 '12 at 08:43
  • Seconded. Post your code, you might be unregistering the listener too soon, or something like that. – Ivan Bartsov Sep 17 '12 at 15:03
  • Without code, i have to re-direct you to similar questions: http://stackoverflow.com/questions/8699262/onproviderenabled-not-working http://stackoverflow.com/questions/6454990/location-service-onproviderenabled-never-called http://stackoverflow.com/questions/7508173/why-isnt-androids-onproviderenabled-method-being-called – Entreco Sep 18 '12 at 09:28

1 Answers1

3

If in onProviderDisabled() you call removeUpdates() for GPS listener, onProviderEnabled() would not be called for GPS adapter.

You must requestLocationUpdates() only at service start and removeUpdates() only at service stop for each providers you want to receive locations from.

Nik
  • 7,114
  • 8
  • 51
  • 75