title: How do I stop GPS/location tracking when my Activity finishes?
body: <p>I have a very simple app for Android that displays a Google Maps view and uses the GPS to track the position (essentially like so): </p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState) {
      // ...
      mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
      // ...
  }
  
  public void onResume() {
      super.onResume();
      mLocationManager.requestLocationUpdates(mProvider, 20000, 1, this);
  }
  
  public void onPause() {
      super.onPause();
      mLocationManager.removeUpdates(this);
  }
  
  public void onLocationChanged(Location location) {
      mPosition = getGeoPointForLocation(location);
      mMapController.setCenter(mPosition);
  }
  </code></pre>
  
  <p>And when I use the following command to exit the application (e.g. through a menu), <strong>the GPS keeps on tracking</strong> - it seems that the Activity is still running:</p>
  
  <pre><code>// ...
  case R.id.menu_exit:
      finish();
  // ...
  </code></pre>
  
  <p>How do I stop the GPS tracking if it does not work by removing the location manager in <code>onPause()</code> and calling <code>finish()</code>? As far as I have read tutorials or other questions, this should be the solution..</p>