0

This is my code that behaves a little strange:

locationOverlay = new MyLocationOverlay(this, map) {
    @Override
    public void onLocationChanged(Location location) {
        super.onLocationChanged(location);
        updatePosition(locationOverlay.getMyLocation());
    }

    @Override
    public void onProviderDisabled(String provider) {
        if(provider.equals(LocationManager.GPS_PROVIDER))
            showNoGPSWarning();
    }
};

showNoGPSWarning shows a Dialog that asks if GPS should be enabled (like this).
Everything wokrs perfectly fine except if I start the Activity with GPS disabled and press "No" in the showNoGPSWarning() dialog. Then my App doesn't listen to GPS changes at all.

If I turn it on, nothing happens. The Google maps API doesn't try to get a GPS signal. If I turn it back off, nothing happens again, onProviderDisabled() is not called.
As I said, this is the only way that happens, if I press "Yes" in the dialog it works.
So how is my dialog affecting the behavior of my App?.

Community
  • 1
  • 1
mmaag
  • 1,534
  • 2
  • 18
  • 24

1 Answers1

1

Once again try to request for location updates when you press yes/no like below. Hope it helps.

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L, 2000.0f, myLocationListener);
Braj
  • 2,164
  • 2
  • 26
  • 44
  • Thank, it works. Any idea what causes the udates to fail only if I press "no"? – mmaag Aug 28 '12 at 13:50
  • When u cm to activity 1st time, gps is off so even if u press no, there is no change in location update as location update is not triggered. So while starting and turning gps off, u hv to trigger location updates i think. In my case, triggering is in onResume method and if user press no, dialog will finish activity. So, I did not face any problem – Braj Aug 28 '12 at 13:56