title: Why does phone state listener get fired multiple times for same state for one call?
body: <p>I am working on fetching recent call log as call get disconnected(outgoing , incoming) either  answered or unanswered.</p>
  
  <p>I am using Phone state listener to fire broadcast when call get disconnected but it getting fired multiple time for one call why so..??</p>
  
  <p>So Please tell me how to fire receiver only once for one call.</p>
  
  <p>here is my code</p>
  
  <pre><code>public class BroadcastReceiver  extends android.content.BroadcastReceiver{
      static boolean iscallended= true;
      Context mContext;
      TelephonyManager telephony;
       private static final String TAG = "CustomBroadcastReceiver";
      CustomPhoneStateListener customPhoneStateListener;
  
      @Override
      public void onReceive(Context context, Intent intent) {
          // TODO Auto-generated method stub
          mContext = context;
          Bundle extras = intent.getExtras();
          if (extras != null) {
              String state = extras.getString(TelephonyManager.EXTRA_STATE);
              Log.w("DEBUG", state);
  
                  telephony = (TelephonyManager)context.getSystemService(context.TELEPHONY_SERVICE);
                 if(customPhoneStateListener==null)
                 {
  
                  customPhoneStateListener = new   CustomPhoneStateListener();
                  telephony.listen(customPhoneStateListener,   PhoneStateListener.LISTEN_CALL_STATE);
                 }
  
  
  
          }
  
  
  
      }
      private class CustomPhoneStateListener extends PhoneStateListener
      {
           private static final String TAG = "CustomPhoneStateListener";
           Handler handler=new Handler();
  
          @Override
          public void onCallStateChanged(int state, String incomingNumber) {
              // TODO Auto-generated method stub
              System.out.println(iscallended+  "  value of iscancelled ");
               switch (state) 
               {
               case TelephonyManager.CALL_STATE_RINGING:
                   if(!incomingNumber.equalsIgnoreCase(""))
                   {
                       //YOUR CODE HERE
  
                   }
                   break;
  
               case TelephonyManager.CALL_STATE_IDLE:
                   if(iscallended)
                   {
                       iscallended = false;
                   System.out.println("IDLE called");
                   Toast.makeText(mContext, "IDLE", Toast.LENGTH_SHORT).show();
                   Intent it = new Intent(mContext,MainActivity.class);
                   it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                   mContext.startActivity(it);
                   }
                   break;
               default:
                   break;
               }
               super.onCallStateChanged(state, incomingNumber);
               telephony.listen(customPhoneStateListener, PhoneStateListener.LISTEN_NONE);
          }
  
  
  
  
  
  
  
      }
  
  }
  </code></pre>
  
  <p>Here's receiver in manifest</p>
  
  <pre><code> &lt;receiver android:name="com.example.calllogs.BroadcastReceiver"&gt;
              &lt;intent-filter &gt;
  
                  &lt;action android:name="android.intent.action.PHONE_STATE"/&gt;
              &lt;/intent-filter&gt;
  
  
          &lt;/receiver&gt;
  </code></pre>