title: Android - Stop PhoneStateListener / BR / UnregisterReceiver
body: <p>I have a problem to stop a PhoneStateListener. I tried to use unregisterReceiver() but it didn't work. I did read the site and saw that I have to use LISTEN.NON but I am unable to do it.<br></p>
  
  <p>My questions are the following : <br>
  1 - where do I have to put my "telephony.listen(listener, PhoneStateListener.LISTEN_NONE);" in my code ?<br>
  2 - do I have to use unregisterReceiver ?<br></p>
  
  <p>My code is not easy to explain and quite long so I won't give all my code but just the main view.<br></p>
  
  <p><strong>In fact : I start a service from timer. This service register a BR</strong></p>
  
  <p>/* First one */</p>
  
  <pre><code>public class TmrSettingsCheck extends BroadcastReceiver
   {
    public void setTimer(long milli)
     { // setRepeating } 
  
    public void onReceive(Context context, Intent intent)         
     {
      // Try to know if we have to start or stop the service
      context.startService(new Intent(context, SvcCall.class));  
      OR
      context.stopService(new Intent(context, SvcCall.class));
     }
   }
  </code></pre>
  
  <p>/* Second one */</p>
  
  <pre><code>public class SvcCall extends Service
   {
    private BroadcastReceiver br_call;
  
    public void onCreate()
     { // Creation }
  
    public int onStartCommand(Intent intent, int flags, int startId)
     {  
      // register the broadcast receiver
      IntentFilter filter = new IntentFilter();
      filter.addAction(ACTION_OUT);
      filter.addAction(ACTION_IN);
      this.br_call = new CallBR(this._context);
      this.registerReceiver(this.br_call, filter);
      return (START_STICKY);
     }
  
    public class CallBR extends ClsCallReceiver
     {
      public CallBR(Context context)  
       { // constructor }
  
      protected void onIncomingCallStarted(String number, Date start) 
       { // XYZ
       }
  
      protected void onIncomingCallEnded(String number, Date start, Date end) 
       { // XYZ }
  
      protected void onOutgoingCallStarted(String number, Date start) 
       { // XYZ }
  
      protected void onOutgoingCallEnded(String number, Date start, Date end) 
       { // XYZ }
  
      protected void onMissedCall(String number, Date start) 
       { // XYZ }
     }
  
    public IBinder onBind(Intent intent)
     { return null; }
  
    public void onDestroy()
    {
     this.unregisterReceiver(this.br_call);          
     super.onDestroy();
     } 
   }
  </code></pre>
  
  <p>/* Third one */</p>
  
  <pre><code>public abstract class ClsCallReceiver extends BroadcastReceiver 
   {
    public static PhonecallStartEndDetector listener;
    String outgoingSavedNumber;
    protected Context savedContext;
    TelephonyManager telephony;
  
    public void onReceive(Context context, Intent intent) 
     {
      savedContext = context;
      if (listener == null)
       listener = new PhonecallStartEndDetector();
  
      if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) 
       {
        listener.setOutgoingNumber(intent.getExtras().getString("android.intent.extra.PHONE_NUMBER"));
        return;
       }
      this.telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); 
      this.telephony.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);
     }
  
    public class PhonecallStartEndDetector extends PhoneStateListener 
     {
      public PhonecallStartEndDetector() 
       { // XYZ }
  
      public void onCallStateChanged(int state, String incomingNumber) 
       { // XYZ }    
     }
  
    protected abstract void onIncomingCallStarted(String number, Date start);
    protected abstract void onOutgoingCallStarted(String number, Date start);
    protected abstract void onIncomingCallEnded(String number, Date start, Date end); 
    protected abstract void onOutgoingCallEnded(String number, Date start, Date end);
    protected abstract void onMissedCall(String number, Date start);   
   }
  </code></pre>