title: GpsStatus.Listener works only if GPS is on
body: <p>in my App I have a <a href="http://developer.android.com/reference/android/location/GpsStatus.Listener.html" rel="nofollow">GpsStatus.Listener</a> to receive events when the user enables or disables GPS. Everything works fine if <strong>GPS is on before I start the app</strong>. In this case I receive a <a href="http://developer.android.com/reference/android/location/GpsStatus.html#GPS_EVENT_STARTED" rel="nofollow">GPS_EVENT_STARTED</a> or a <a href="http://developer.android.com/reference/android/location/GpsStatus.html#GPS_EVENT_STOPPED" rel="nofollow">GPS_EVENT_STOPPED</a> everytime I toggle GPS on or off.</p>
  
  <p>The problem is if <strong>GPS is off while app is starting</strong>. In this case I don't receive an event if I toggle GPS on or off.</p>
  
  <p>Can someone explain that to me?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public class GPSTracker implements android.location.GpsStatus.Listener {
  
      private final Context context;
      private final LocationListener locListener;
      private LocationManager locationManager;
      private boolean isGPSEnabled = false;
  
      public GPSTracker(Context context, LocationListener locListener) {
              this.context = context;
              this.locListener = locListener; 
              setupGPS();
      }
  
      private void setupGPS() {
              locationManager = (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE);                
              locationManager.addGpsStatusListener(this);
              isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
              if(!isGPSEnabled) {
                      Toast.makeText(getContext(), "GPS disabled", Toast.LENGTH_SHORT).show();
              } else {        
                      locationManager.removeUpdates(locListener);
                      locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME, MIN_DISTANCE, locListener);
              }
      }
  
      @Override
      public void onGpsStatusChanged(int event) {
              Log.e("onGpsStatusChanged", event+""); 
              switch(event) {
              case GpsStatus.GPS_EVENT_STARTED:
                      Log.e("onGpsStatusChanged", "GPS_EVENT_STARTED");
                      break;
              case GpsStatus.GPS_EVENT_STOPPED:
                      Log.e("onGpsStatusChanged", "GPS_EVENT_STOPPED");
                      break;
              }
      }
  </code></pre>
  
  <p>So, my logcat output is (if GPS is on while starting):</p>
  
  <ul>
  <li>GpsStatusChanged(24638): 1    // app starts</li>
  <li>GpsStatusChanged(24638): GPS_EVENT_STARTED</li>
  <li>GpsStatusChanged(24638): 4    // searching for fixes</li>
  <li>GpsStatusChanged(24638): 4</li>
  <li>GpsStatusChanged(24638): 2    // toggle GPS off</li>
  <li>GpsStatusChanged(24638): GPS_EVENT_STOPED</li>
  </ul>
  
  <p>Output with GPS off: nothing.</p>