title: show alertdialog box for disabling gps when stop using the app
body: <p>I have an application which uses GPS and in the activity that the user takes action ,when pressing the "Get location" button ,it appears an alertdialog and from there the user enables the GPS.</p>
  
  <p>But, when I exit the app or when I exit that activity I want to be able to disable the app.</p>
  
  <p>I read that I must override the onPause method but nothing happens when I press the back arrow or when  I press the home button.</p>
  
  <pre><code>GPSTracker gps;
  protected LocationManager locationManager;
  boolean isGPSEnabled = true;
  boolean isNetworkEnabled = true;
  
  @Override
  public void onPause() {
      super.onPause();
      gps = new GPSTracker(MainActivity.this);
  
      try{
      locationManager = (LocationManager) this
             .getSystemService(LOCATION_SERVICE);
  
      // getting GPS status
     isGPSEnabled = locationManager
              .isProviderEnabled(LocationManager.GPS_PROVIDER);
  
      // getting network status
      isNetworkEnabled = locationManager
              .isProviderEnabled(LocationManager.NETWORK_PROVIDER);
  
      if (isGPSEnabled &amp;&amp; isNetworkEnabled) {
          gps.showSettingsAlertDisable();
  
      }
  
      }catch (Exception e) {
          e.printStackTrace();
      }
  
  }
  
  
  public void showSettingsAlertDisable(){
          AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);
  
          // Setting Dialog Title
          alertDialog.setTitle("GPS settings");
  
          // Setting Dialog Message
          alertDialog.setMessage("Do you want to disable GPS?");
  
          // On pressing Settings button
          alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog,int which) {
  
                  Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                  mContext.startActivity(intent);
              }
          });
  
          // on pressing cancel button
          alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int which) {
              dialog.cancel();
              }
          });
  
          // Showing Alert Message
          alertDialog.show();
      }
  </code></pre>