title: Android activity not getting broadcast from local service
body: <p>From the examples this looked straightforward. Maybe you can show me what I did wrong. I can't get an activity to receive a broadcast sent from a local service.</p>
  
  <p>I have Activity1 that start Service1:</p>
  
  <pre><code>startService(new Intent(Activity1.this, Service1.class));
  </code></pre>
  
  <p>Activity1 then starts Activity2:</p>
  
  <pre><code>startActivity(new Intent(Activity1.this, Activity2.class));
  </code></pre>
  
  <p>Service1, a local service, listens for downloads:</p>
  
  <pre><code>protected final BroadcastReceiver service2DownloadBroadcastReceiver = new BroadcastReceiver()
  {
      public void onReceive(final Context context, final Intent intent)
      {
          ...
          broadcastDownloadFinished(Uri.fromFile(downloadedFile));
  </code></pre>
  
  <p>The broadcast receiver of Service1 then broadcasts its own message:</p>
  
  <pre><code>protected Intent broadcastDownloadFinished(final Uri uri)
  {
      final Intent intent = new Intent(ACTION_DOWNLOAD_FINISHED).setData(checkNotNull(uri));
      sendBroadcast(intent);
  </code></pre>
  
  <p>Activity2, which is in the foreground at the time, listens for the ACTION_DOWNLOAD_FINISHED intent using its own broadcast receiver:</p>
  
  <pre><code>private final BroadcastReceiver activity2DownloadBroadcastReceiver = new BroadcastReceiver()
  {
      public void onReceive(final Context context, final Intent intent)
      {
          Log.i(Activity2.class.getSimpleName(), "Received download event: " + intent.getAction() + " " + intent.getData());
  </code></pre>
  
  <p>Activity2 of course registers the receiver:</p>
  
  <pre><code>protected void onResume()
  {
      super.onResume();
      final IntentFilter downloadIntentFilter = new IntentFilter();
      downloadIntentFilter.addAction(ACTION_DOWNLOAD_FINISHED);
      registerReceiver(activity2DownloadBroadcastReceiver, downloadIntentFilter);
  </code></pre>
  
  <p>In case it matters, <code>ACTION_DOWNLOAD_FINISHED</code> is something like <code>"com.example.intent.action.DOWNLOAD_FINISHED"</code>.</p>
  
  <p>Service1 receives the download manager event in its receiver and apparently broadcasts its own custom event, but Activity2 never seems to receive it. What did I do wrong? Is it a problem to broadcast an intent in the middle of processing another one? (I wouldn't think so---this is asynchronous, right?)</p>
  
  <p><em>Update:</em> Just to make sure there is no problem sending a broadcast in the middle of receiving a broadcast, I changed my broadcast code to actually perform the broadcast three seconds later on the main thread:</p>
  
  <pre><code>    Log.i(getClass().getSimpleName(), "...ready to broadcast");     
      final Intent intent = new Intent(ACTION_DOWNLOAD_FINISHED).setData(checkNotNull(uri));
      mainThreadHandler.postDelayed(new Runnable()
      {
          public void run()
          {
              Log.i(getClass().getSimpleName(), "...broadcasting");
              sendBroadcast(intent);
              Log.i(getClass().getSimpleName(), "...broadcasted");                
          }
      }, 3000);
      Log.i(getClass().getSimpleName(), "...scheduled to broadcast");
  </code></pre>
  
  <p>As expected, the log says:</p>
  
  <pre><code>...ready to broadcast
  ...scheduled to broadcast
  ...broadcasting
  ...broadcasted
  </code></pre>
  
  <p>Yet nothing is received in the activity. Please help.</p>