title: Remove Location Listener
body: <p>I want after open dialog and click on location button, detect user's location and show user's location and then user dismiss dialog, location listener removes and not get location from <code>onLocationChanged</code>, I try used <code>locationManager.removeUpdate(locListener)</code>on override <code>dismiss</code> but not any chance and location after dismiss again shows! why? How can i detect user's location after show dialog and after detect location, location listener remove? Thanks</p>
  
  <p>EDIT:</p>
  
  <blockquote>
  <pre><code>public class DialogTest extends Dialog implements
  android.view.View.OnClickListener {
  </code></pre>
  </blockquote>
  
  <pre><code>Context context;
  LocationManager locationManager;
  LocationListener locationListener;
  
  Location location;
  
  public DialogTest(Context context) {
      super(context);
      // TODO Auto-generated constructor stub
      requestWindowFeature(Window.FEATURE_NO_TITLE);
      this.context = context;
      setContentView(R.layout.profile_dialog);
  
      getWindow().setBackgroundDrawableResource(R.drawable.background_dialog);
  
      firstAccessLocation=true;
  
      setCancelable(true);
      initialize();
  }
  @Override
  public void onClick(View arg0) {
      // TODO Auto-generated method stub
      findAddress();
  }
  
  private void findAddress() {
      // if (gpsCheckBox.isChecked()) {
      locationManager = (LocationManager) context
              .getSystemService(Context.LOCATION_SERVICE);
      locationListener = new GPSLocationListener();
      locationManager.requestLocationUpdates(locationManager.GPS_PROVIDER, 0,
              0, locationListener);
      locationManager.requestLocationUpdates(
              locationManager.NETWORK_PROVIDER, 0, 0, locationListener);
      // }
  }
  
  private void stopTracking(){
      if(locationManager!=null){
          locationManager.removeUpdates(locationListener);
      }
  }
  
  @Override
  public void dismiss() {
      // TODO Auto-generated method stub
      stopTracking();
      gpsTurnOff();
      super.dismiss();
  }
  
  public class GPSLocationListener implements LocationListener {
  
      @Override
      public void onLocationChanged(Location loc) {
          // TODO Auto-generated method stub
          if(location!=null)
              Log.e("location", location.getLatitude()+"");
          location = loc;
          if (location != null&amp;&amp; firstAccessLocation) {
              setAddress(location.getLatitude(), location.getLongitude());
              firstAccessLocation=false;
          }
          Toast.makeText(context, "changed", Toast.LENGTH_LONG).show();
          Log.e("location", "changed");
      }
  
      @Override
      public void onProviderDisabled(String arg0) {
          // TODO Auto-generated method stub
  
      }
  
      @Override
      public void onProviderEnabled(String arg0) {
          // TODO Auto-generated method stub
  
      }
  
      @Override
      public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
          // TODO Auto-generated method stub
  
      }
  
  }
  </code></pre>
  
  <p>}</p>