title: Send Intent from Broadcast Receiver with Extras to Activity (Problems with a Service)
body: <p>I have been looking for that so much and I haven't found the solution.</p>
  
  <p>My applications calls a number all time, and when it receives an incoming call with an exactly number it stops (dies).
  My idea is that:</p>
  
  <ol>
  <li>Activity launches Service that does the job of calling</li>
  <li>A BroadcastReceiver that is expecting for the incoming call</li>
  </ol>
  
  <p>So, I want to use the BroadcastReceiver to kill the Activity, but I haven't found any solution to this. To try another thing, I tried to send an Intent with Extras but the Extras have become null.</p>
  
  <p>I'm open to use any other solution that solve it!</p>
  
  <p>Thank-you very very much!</p>
  
  <p><strong>UPDATED CODE TO DO THE RECOMMENDATION OF Kurtis Nusbaum</strong> 
  <strong>I see that the problem is in the Service when it makes the call, so I put all my code</strong></p>
  
  <p>Here my code:</p>
  
  <pre><code>package com.comunicacio;
  
  import android.app.Activity;
  import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  import android.content.IntentFilter;
  import android.os.Bundle;
  import android.util.Log;
  
  public class Comunicacio extends Activity {
  
      IntentFilter filter;
  
      private BroadcastReceiver receiver = new BroadcastReceiver() {
          @Override
          public void onReceive(Context context, Intent intent) {
              Log.i("BYE", "OOOOOOOOOOOOK");
              finish();
          }
      };
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          filter = new IntentFilter();
          filter.addAction("com.comunicacio.FINALITZAR");
  
          startService(new Intent(this, Servicio.class));
      }
  
      @Override
      protected void onResume() {
          super.onResume();
          registerReceiver(receiver, filter);
      }
  
      @Override
      protected void onPause() {
          super.onPause();
          unregisterReceiver(receiver);
      }
  
  }
  </code></pre>
  
  <p>The BroadcastReceiver:
      package com.comunicacio;</p>
  
  <pre><code>import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  import android.os.Bundle;
  import android.telephony.TelephonyManager;
  import android.util.Log;
  
  public class DetectarCridada extends BroadcastReceiver {
      public static final String CUSTOM_INTENT = "com.comunicacio.FINALITZAR";
  
      @Override
      public void onReceive(Context context, Intent intent) {
          Bundle bundle = intent.getExtras();
  
          if (bundle == null)
              return;
  
          String state = bundle.getString(TelephonyManager.EXTRA_STATE);
  
          if (state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING)) {
              String phonenumber = bundle
                      .getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
  
              Log.i("BYE", "UUUUUUUUUUUUUUUUL");
  
              // if (es_acceptat(phonenumber)) {
              Intent i = new Intent();
              i.setAction(CUSTOM_INTENT);
              context.sendBroadcast(i);
              // }
          }
      }
  
      private boolean es_acceptat(String telefono) {
          if (telefono.equals("123"))
              return true;
          return false;
      }
  }
  </code></pre>
  
  <p>And Manifest:
      
      </p>
  
  <pre><code>    &lt;uses-sdk android:minSdkVersion="10" /&gt;
  
      &lt;application
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name" &gt;
          &lt;activity
              android:label="@string/app_name"
              android:name="Comunicacio" &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;receiver android:name=".DetectarCridada" &gt;
              &lt;intent-filter &gt;
                  &lt;action android:name="android.intent.action.PHONE_STATE" /&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
          &lt;service
              android:enabled="true"
              android:name=".Servicio" /&gt;
  
          &lt;activity android:name=".Call" /&gt;
      &lt;/application&gt;
  
      &lt;uses-permission android:name="android.permission.CALL_PHONE" /&gt;
      &lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <p>The Service Sercivio.java:
      package com.comunicacio;</p>
  
  <pre><code>import android.app.Service;
  import android.content.Context;
  import android.content.Intent;
  import android.os.IBinder;
  import android.telephony.PhoneStateListener;
  import android.telephony.TelephonyManager;
  import android.util.Log;
  import android.widget.Toast;
  
  public class Servicio extends Service {
      private static final String TAG = "MyService";
      boolean hem_cridat = false;
      int telefono = 123;
  
      @Override
      public IBinder onBind(Intent intent) {
          return null;
      }
  
      @Override
      public void onCreate() {
          Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show();
          Log.d(TAG, "onCreate");
          EndCallListener callListener = new EndCallListener();
          TelephonyManager mTM = (TelephonyManager) this
                  .getSystemService(Context.TELEPHONY_SERVICE);
          mTM.listen(callListener, PhoneStateListener.LISTEN_CALL_STATE);
      }
  
      @Override
      public void onDestroy() {
          Toast.makeText(this, "My Service Stopped", Toast.LENGTH_LONG).show();
      }
  
      @Override
      public void onStart(Intent intent, int startid) {
          Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show();
          call();
      }
  
      private class EndCallListener extends PhoneStateListener {
          private static final String LOG_TAG = "Comunicacio:";
  
          @Override
          public void onCallStateChanged(int state, String incomingNumber) {
              switch (state) {
              case TelephonyManager.CALL_STATE_RINGING:
                  Log.i(LOG_TAG, "RINGING, number: " + incomingNumber);
                  break;
              case TelephonyManager.CALL_STATE_OFFHOOK:
                  Log.i(LOG_TAG, "OFFHOOK");
                  hem_cridat = true;
                  break;
              case TelephonyManager.CALL_STATE_IDLE:
                  Log.i(LOG_TAG, "IDLE");
                  if (hem_cridat) {
                      hem_cridat = false;
                      try {
                          Log.i(LOG_TAG, "Cridant!");
                          call();
                      } catch (Exception e) {
                          e.printStackTrace();
                      }
                  }
                  break;
              }
          }
      }
  
      private void call() {
      /* THE PROBLEM IS THERE !!! If I don't do that, it works! */
      /*  Intent i = new Intent(getBaseContext(), Call.class);
          i.putExtra("NUMERO", telefono);
          i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          getApplication().startActivity(i);
          ++telefono; */
      }
  }
  </code></pre>
  
  <p>And finally Call.java:
      package com.comunicacio;</p>
  
  <pre><code>import android.app.Activity;
  import android.content.Intent;
  import android.net.Uri;
  import android.os.Bundle;
  
  public class Call extends Activity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          Bundle b = getIntent().getExtras();
          Intent i = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"
                  + b.getInt("NUMERO")));
          startActivity(i);
      }
  }
  </code></pre>
  
  <p>Thank-you very very much!</p>