title: BroadcastReceiver not receiving Intent from inside Service
body: <p>I've got an Activity and a Service in my app and I'm sending broadcasts to each of them from the other. While my activity receives the broadcast that's sent from my Service, my Service doesn't pick up the broadcast sent from my Activity.</p>
  
  <p>Here's some of my code:</p>
  
  <p>Activity</p>
  
  <pre><code>    @Override
  public void onResume()
  {
      Log.i(TAG, "in onResume");
  
      IntentFilter messageFilter = new IntentFilter(Constants.MESSAGE);
      messageReceiver receiver = new messageReceiver();
      registerReceiver(receiver, messageFilter);
  
      startService(new Intent(this, Server.class));
  
      super.onResume();
  }
  
  public class messageReceiver extends BroadcastReceiver
  {
      @Override
      public void onReceive (Context context, Intent intent)
      {
          Log.i(TAG, "in messageReceiver");
          serverStatus.setText(intent.getStringExtra(Constants.MESSAGE));
      }
  }
  
  @SuppressLint("ParserError")
  public OnClickListener btnSendClicked = new OnClickListener() {
  
      public void onClick(View v) {
          Log.i(TAG, "btnSend clicked");
  
  // This broadcast is NOT picked up by my Service
          Intent sendClicked = new Intent(Constants.SEND_CLICKED);
          sendBroadcast(sendClicked);
      }
  };
  </code></pre>
  
  <p>Service</p>
  
  <pre><code>    @SuppressLint({ "ParserError", "ParserError", "ParserError" })
  public class btnSendClickedReceiver extends BroadcastReceiver
  {
      @Override
      public void onReceive(Context arg0, Intent arg1) {
  
          // Do some stuff
      }
  };
  
  @Override
  public int onStartCommand(Intent intent, int flags, int startId)
  {
      Log.i(TAG, "in onStartCommand");
  
      SERVERIP = getLocalIpAddress();
  
      IntentFilter sendClickedFilter = new IntentFilter(Constants.SEND_CLICKED);
      btnSendClickedReceiver receiver = new btnSendClickedReceiver();
      registerReceiver(receiver, sendClickedFilter);
  
      runServer();
  
      return START_STICKY;
  }
  
  @SuppressLint("ParserError")
  public void runServer()
  {
      try
      {
          if (SERVERIP != null)
          {
              Log.i(TAG, "inside runServer");
  
  // This broadcast is picked up by my activity:
              Intent intent = new Intent(Constants.MESSAGE);
              intent.putExtra(Constants.MESSAGE, "Listening on IP: " + SERVERIP);
              sendBroadcast(intent);
              serverSocket = new ServerSocket(SERVERPORT);
              while (true)
              {
                  client = serverSocket.accept();
                  Log.i(TAG, "connected");
  
                  Intent connectedIntent = new Intent(Constants.MESSAGE);
                  connectedIntent.putExtra(Constants.MESSAGE, "Connected");
                  sendBroadcast(connectedIntent);
  
  
              }
          }
          else
          {
              // no internet connection
          }
      } catch (Exception e)
      {
          //Error
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>Manifest</p>
  
  <pre><code>        &lt;activity
          android:name=".MainActivity"
          android:label="@string/title_activity_main" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
  
              &lt;action android:name="message"/&gt;
              &lt;action android:name="SendClicked"/&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  
      &lt;service android:name=".Server" android:process=":remote"&gt;
      &lt;/service&gt;
  </code></pre>
  
  <p>I have been trying to debug this for days, but I'm not sure what the problem is. Any help is appreciated.</p>