title: Listening to only one phone state
body: <p><br>
  I am using the PhoneState Action in my Android app, but there is a problem, Wen I get the number from an incoming call during ringing state, it works fine but after I pick the call my BroadCastReceiver crashes because the intent bundle is null coz there is no number to fetch. </p>
  
  <p>How do I make sure I am listening to only to the Ringing state and not any other weird stuff:</p>
  
  <p>Here is my code:</p>
  
  <pre><code>package com.messageHider;
  
  import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  import android.database.Cursor;
  import android.database.sqlite.SQLiteDatabase;
  import android.os.Bundle;
  import android.telephony.PhoneStateListener;
  import android.telephony.TelephonyManager;
  import android.util.Log;
  import android.widget.Toast;
  
  public class incomingCallReceiver extends BroadcastReceiver {
      @Override
      public void onReceive(Context context, Intent intent) {
          Bundle bundle=intent.getExtras();
          String number=bundle.getString("incoming_number");
          dbConnection connection=new dbConnection(context);
          SQLiteDatabase db=connection.getReadableDatabase();
          Cursor cursor=db.query(dbConnection.TABLE_CONTACTS, null, dbConnection.CONTACT+"=?",new String[]{number}, null, null, null);
          cursor.moveToFirst();
          int count=cursor.getCount();
          Toast.makeText(context,String.valueOf(count), Toast.LENGTH_LONG).show();
      }
  }
  </code></pre>
  
  <p>Here is my manifest:
  
  </p>
  
  <pre><code>&lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt;
      &lt;activity android:name=".messageHider"
                android:label="@string/app_name"&gt;
  
      &lt;/activity&gt;
      &lt;activity android:name=".sms"/&gt;
      &lt;activity android:name=".viewsms"/&gt;
      &lt;activity android:name=".hiddenMessages"&gt;&lt;/activity&gt;
      &lt;activity android:name=".viewContacts"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
      &lt;service android:name=".smsService"/&gt;
      &lt;receiver android:name=".smsReceiver"&gt;
          &lt;intent-filter android:priority="100"&gt;
              &lt;action android:name="android.provider.Telephony.SMS_RECEIVED"/&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
      &lt;receiver android:name=".smsSentReceiver"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.provider.Telephony.SMS_SENT"/&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
      &lt;receiver android:name=".incomingCallReceiver"&gt;
          &lt;intent-filter android:priority="100"&gt;
              &lt;action android:name="android.intent.action.PHONE_STATE"/&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
  &lt;/application&gt;
  &lt;uses-permission android:name="android.permission.READ_SMS"/&gt;
  &lt;uses-permission android:name="android.permission.WRITE_SMS"/&gt;
  &lt;uses-permission android:name="android.permission.RECEIVE_SMS"/&gt;
  &lt;uses-permission android:name="android.permission.SEND_SMS"/&gt;
  &lt;uses-permission android:name="android.permission.READ_CONTACTS"/&gt;
  &lt;uses-permission android:name="android.permission.READ_PHONE_STATE"/&gt;
  </code></pre>
  
  <p></p>