title: Trying to pass value to Broadcast Receiver from Activity crashes Application
body: <p>I am trying to pass a value to a Broadcast Receiver from Activity based on <a href="https://stackoverflow.com/questions/21422656/how-to-pass-value-from-activity-to-broadcastreceiver">this</a> question.</p>
  
  <p>However, doing so crashes my application. Here is my code of the Activity.</p>
  
  <pre><code>private void setAlarm(Calendar targetCal)
  {
  
      Intent in = new Intent("my.action.string");
      in.putExtra("ALARM_NO", tempx);
      sendBroadcast(in);
  
      Intent alarmintent = new Intent(AddAlarm.this, AlarmReceiver.class);
      PendingIntent sender = PendingIntent.getBroadcast(AddAlarm.this, pen, alarmintent, PendingIntent.FLAG_ONE_SHOT);
      AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
      alarmManager.setExact(AlarmManager.RTC_WAKEUP, targetCal.getTimeInMillis(), sender);
  
  
  }
  </code></pre>
  
  <p>And here is the Broadcast Receiver code as well:</p>
  
  <pre><code>public void onReceive(final Context context, Intent intent) {
      int state;
      String action = intent.getAction();
  
      Log.i("Receiver", "Broadcast received: " + action);
  
      if(action.equals("my.action.string"))
      {
          state = intent.getIntExtra("ALARM_NO",0);
  
      }
  
      if(state==1) {
  
          //intent to call the activity which shows on ringing
          Intent myIntent = new Intent(context, Time_Date.class);
          myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          context.startActivity(myIntent);
      }
  
      if(state==2)
      {
          //intent to call the activity which shows on ringing
          Intent myIntent = new Intent(context, AlarmLaunch2.class);
          myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          context.startActivity(myIntent);
      }
  </code></pre>
  
  <p>And this is what i obtain in the logcat.</p>
  
  <pre><code>&gt; 07-21 16:40:40.769  26721-26721/zyia.alarm.zyia.zyia E/AndroidRuntime﹕ FATAL EXCEPTION: main
      Process: zyia.alarm.zyia.zyia, PID: 26721
      java.lang.RuntimeException: Unable to start receiver zyia.alarm.zyia.zyia.AlarmReceiver: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
              at android.app.ActivityThread.handleReceiver(ActivityThread.java:2616)
              at android.app.ActivityThread.access$1700(ActivityThread.java:151)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1380)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:135)
              at android.app.ActivityThread.main(ActivityThread.java:5254)
              at java.lang.reflect.Method.invoke(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:372)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
       Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
              at zyia.alarm.zyia.zyia.AlarmReceiver.onReceive(AlarmReceiver.java:29)
              at android.app.ActivityThread.handleReceiver(ActivityThread.java:2609)
              at android.app.ActivityThread.access$1700(ActivityThread.java:151)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1380)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:135)
              at android.app.ActivityThread.main(ActivityThread.java:5254)
              at java.lang.reflect.Method.invoke(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:372)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
  </code></pre>
  
  <p>So , whats causing the null pointer exception? and how to fix this ? Any help will be appreciated.</p>