title: unable to unregister phonestatelistener
body: <p>I am trying to integrate the following into my code to unregister phonestatelistener </p>
  
  <pre><code>TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); 
  if(mgr != null) {
      mgr.listen(phoneStateListener, PhoneStateListener.LISTEN_NONE); 
  } 
  </code></pre>
  
  <p>I have a service which runs in the background and checks if a number is on a blocking list. If yes then it calls <code>PhonestateListener</code> </p>
  
  <pre><code>TelephonyManager mTM = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
  mTM.listen(new phoneStateListener(NumberInbound,Msg_to_display,mTM), PhoneStateListener.LISTEN_CALL_STATE);
  </code></pre>
  
  <p>but when i remove a number from the blocking list I want to unregister <code>phonestatelistner</code>. Instead what happens is that <code>phonestatelistener</code> is always registered and the msisdn which I previously removed is still blocked !</p>
  
  <p>can you help ?  </p>
  
  <p>Code for <code>phonestatelistner</code></p>
  
  <pre><code>class phoneStateListener extends PhoneStateListener {
  
      String inbounda;
      int MessagetoDisplay;
      String msg;
      String reply;
      TelephonyManager myt;
      MyService calltoService;
      boolean mBound = false;
      private static final String TAG = "PHONELISTENER";
  
      phoneStateListener(String inbound,int Message,TelephonyManager t) {
          inbounda = inbound;
          MessagetoDisplay = Message;
          myt = t;
      }
  
      public void onCallStateChanged(int state, String incomingNumber) {
  
          if(!incomingNumber.equals(inbounda)){
  
          } else { 
  
              final String TAG = "Phone call"; 
              ITelephony telephonyService;
          //new code
              Log.v("Phone State", "state:"+state);
  
              switch (state) {
                  case TelephonyManager.CALL_STATE_IDLE:
                     Log.v("Phone State", "incomingNumber:"+incomingNumber+" ended");
                      break;
                  case TelephonyManager.CALL_STATE_OFFHOOK:
                      Log.v("Phone State", "incomingNumber:"+incomingNumber+" picked up");
                      break;
                  case TelephonyManager.CALL_STATE_RINGING:
                      if(inbounda.equalsIgnoreCase(incomingNumber)){
                          Log.v("ARE THE SAME...............................", "incomingNumber:"+incomingNumber+ "inbound:"+ inbounda + "MSG TO DISPLAY" +msg);
  
                          try{
                              Class c = Class.forName(myt.getClass().getName());   
                              Method m = c.getDeclaredMethod("getITelephony");   
                              m.setAccessible(true);   
                              telephonyService = (ITelephony) m.invoke(myt);   
                              telephonyService.silenceRinger();   
                              telephonyService.endCall();
                          } catch (Exception e) {
                              e.printStackTrace();
                          }
  
                          try{
                              Thread.currentThread().sleep(4000);
                              replyChecker(MessagetoDisplay);
                          } catch(InterruptedException ie){
  
                          }
                      }
                      break;
                  default:
                      break;
              }
          }
      }
  
      public String replyChecker(int Check) {
          SmsManager mySMS = SmsManager.getDefault();
          String destination = inbounda;     
          //open - to be extended to allow user to define own tailored message 
          String Meeting = "Sorry I am at a meeting. Graham  ";
          String Gym = "I am currently at the gym and will respond to you later. Graham ";
          String NewYearsEve = "Happy New Year to you and your loved ones. Graham ";
  
          if(Check == 1) {
              Log.v("HERE NOW1",":");
              reply  = Meeting;
  
              mySMS.sendTextMessage(destination, null, Meeting, null, null);
              return reply;
          } else if (Check == 2) {
              Log.v("HERE NOW2",":");
              reply = Gym;
              mySMS.sendTextMessage(destination, null, Gym, null, null);
              return reply;
          } else if (Check == 3) {
              Log.v("HERE NOW3",":");
              reply = NewYearsEve;
              mySMS.sendTextMessage(destination, null, NewYearsEve, null, null);
              return reply;
          }
          // TODO Auto-generated method stub
          return reply;
      }
  }
  </code></pre>