title: How to get notified when the gps in disabled by the user in android?
body: <p>I am creating an app which uses GPS. For the first time in <strong><code>onCreate()</code></strong> I am checking whether the GPS is enabled or not. And if its not enabled then I am sending the user to the setting menu to set the GPS enabled.</p>
  
  <p>Once the GPS is enabled then I starts executing my stuff. <strong><em>But if in between the user stops the GPS scrolling on Notification manager then how would I know this?</em></strong></p>
  
  <p>Because my method executed only once when the GPS is not enabled. After that its not getting executed when it is disabled again.</p>
  
  <p><strong><code>I just want to know whenever in between the work the GPS is disabled by the user. Just this information is required.</code></strong></p>
  
  <p>Here is my code.</p>
  
  <pre><code>class LocationFinderService extends Service{
  
      boolean gps_enabled;
      LocationManager locationManager;
      @Override
      public void onCreate() {
          // TODO Auto-generated method stub
          super.onCreate();
          locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
          if(!isGpsEnabled())
          {
              startGpsForLocation();
              stopSelf();
          }
  
      }
      @Override
      public IBinder onBind(Intent intent) {
          // TODO Auto-generated method stub
          return null;
      }
  
      public boolean isGpsEnabled()
      {
          gps_enabled = (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)&amp;&amp; locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER));
          Log.i("Log", "Gps:  "+gps_enabled);
          return gps_enabled;
      }
  
      public void startGpsForLocation()
      {
          Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
          intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) ;
          startActivity(intent);
          Toast.makeText(this, "Please start the GPS", Toast.LENGTH_LONG).show();
      }
  }
  </code></pre>
  
  <p><strong>I am calling this service on the button click of the Activity class.</strong></p>
  
  <p>Any help would be appreciated.</p>