title: Pass the values from the BroadcastReceiver to an activity
body: <p>I have used the following code to get the phone number. I stored the number in a static variable. When I tried to use that variable in another activity, it throws NullPointer Exception.</p>
  
  <pre><code>package com.income;
  
  import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  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 {
      static String info = null;
      static String phonenumber;
  
      @Override
      public void onReceive(Context context, Intent intent) {
          // TODO Auto-generated method stub
  
          Bundle bundle = intent.getExtras();
          if (null == bundle)
              return;
          Log.i("IncomingCallReceiver", bundle.toString());
          String state = bundle.getString(TelephonyManager.EXTRA_STATE);
          Log.i("IncomingCallReceiver", "State: " + state);
          if (state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING)) {
              phonenumber = bundle
                      .getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
              // String d=bundle.getString(TelephonyManager.EXTRA_STATE_IDLE)
              Log.i("IncomingCallReceiver", "Incomng Number: " + phonenumber);
              info = phonenumber;
          }
          if (state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_IDLE)) {
              Toast.makeText(context, info, Toast.LENGTH_LONG).show();
              Intent intent1 = new Intent(context, MissedCall.class);
              intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
              context.startActivity(intent1);
          }
      }
  
  }
  </code></pre>