title: LocationManager.removeUpdates(listener) not removing location listener
body: <p>My app scenario is that I want to track employees location. I have a broadcastreceiver which listens device boot broadcast and register an alarm manager. When alarm manager ticks, it registers two location listeners, one to listen to gps and other for network. I want that when I got first location update in onLocationChange() method, save location and unregister that location listener so that when alarm manager ticks again, it does not get duplicate. To unregister, I have location listeners as static objects to access them in onLocationChange(). But I have found that it is NOT removing location listener. Here is my code example:</p>
  
  <pre><code> public class BootTimeServiceActivator extends BroadcastReceiver {
  
      @Override
      public void onReceive(Context context, Intent intent) {
          // TODO Auto-generated method stub
          Calendar calendar = Calendar.getInstance();
          AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
          Intent mIntent = new Intent(context, MyBroadCastReceiver.class);
          PendingIntent mPendingIntent = PendingIntent.getBroadcast(context, 0, mIntent, PendingIntent.FLAG_CANCEL_CURRENT);
          am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 20 * 60 * 1000, mPendingIntent);
  
  
      }
  
      }
  
  //..........
  
      public class MyBroadCastReceiver extends BroadcastReceiver{
  
      public static LocationManager locationManager;
      public static MyLocationListener networkLocationListener;
      public static MyLocationListener gpsLocationListener;
  
  
  
      @Override
      public void onReceive(Context context, Intent intent) {
          // TODO Auto-generated method stub
          Toast.makeText(context, "Alarm has been called...", Toast.LENGTH_SHORT).show();
          initLocationListeners(context);
          registerLocationListeners();
  
      }
  
      public void initLocationListeners(Context context) {
          locationManager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
          networkLocationListener = new MyLocationListener(context);
          gpsLocationListener = new MyLocationListener(context);
  
      }
  
      public void registerLocationListeners() {
          locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 100, 0, gpsLocationListener);
          locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 100, 0, gpsLocationListener);
  
      }
  
  }
  
  \\.....
  
      public class MyLocationListener implements LocationListener {
  
      Context context;
  
      public MyLocationListener(Context context) {
          this.context = context;
      }
  
      @Override
      public void onLocationChanged(Location location) {
          if(location != null) {
              SDCardService sdService = new SDCardService(context);
              try {
                  sdService.logToDB(location);
              } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
              Log.d("provider",location.getProvider());
              if(location.getProvider().equals(LocationManager.GPS_PROVIDER)) {
                  MyBroadCastReceiver.locationManager.removeUpdates(MyBroadCastReceiver.gpsLocationListener);
              }
              else if(location.getProvider().equals(LocationManager.NETWORK_PROVIDER)) {
                  MyBroadCastReceiver.locationManager.removeUpdates(MyBroadCastReceiver.networkLocationListener);
              }
  
  
  
          }
  
  
      }
  </code></pre>
  
  <p>Can anyone guide me where I am wrong?</p>