title: How can i send registration id getting from GCM in broadcastReceiver to main Activity
body: <p>I am android developer developing an app.Here I am getting registration id from GCM and saving it in a string, now i want to send this registration id from broadcastreceiver class to my mainActivity class so that I can send this value to my server.I am trying to use intent but force close occur always.</p>
  
  <p>code for GcmBroadcastreceiver.class is </p>
  
  <p>public void onReceive(Context context, Intent intent)
      {</p>
  
  <pre><code>        String action=intent.getAction();
          Log.d("msg", action);
  
      if(action.equals("com.google.android.c2dm.intent.REGISTRATION"))
          {
  
              Log.d("msg", "within if loop");
  
              Bundle bundle = intent.getExtras();
              if (bundle != null) {
                  Set&lt;String&gt; keys = bundle.keySet();
                  Iterator&lt;String&gt; it = keys.iterator();
                  Log.d("msg","Dumping Intent start");
                  while (it.hasNext()) {
                      String key = it.next();
                  //    Log.d("msg","[" + key + "=" + bundle.get(key)+"]");
                Toast.makeText(context,("msg"+"[" + key + "=" + bundle.get(key)+"]"), Toast.LENGTH_LONG).show();
                  }
                  Log.d("msg","Dumping Intent end");
  
              }
              String registrationId=intent.getStringExtra("registration_id");
              Toast.makeText(context, "reg is"+registrationId, Toast.LENGTH_LONG).show();
  
              Intent in=new Intent(context,MainActivity.class);
              in.putExtra("RegID", registrationId);
              context.startActivity(in);
              Toast.makeText(context, "Intent is send to mainactivity class", Toast.LENGTH_LONG).show();
  
  
  
           //   Log.d("regid", registrationId);
              String error=intent.getStringExtra("error");
              //Log.d("error", error);
              String unregistered=intent.getStringExtra("unregistered");
          //  Log.d("unregistered", unregistered);
          }
  
          else if(action.equals("com.google.android.c2dm.intent.RECEIVE"))
          {
              String data1=intent.getStringExtra("data1");
              Log.d("data1::",data1);
              String data2=intent.getStringExtra("data2");
              Log.d("data2::",data2);
          }
  </code></pre>