title: Android - Unable to receive local broadcast in my activity from service
body: <p>I have my main activity that start a service (Location service) and I want that service to broadcast the new location each time a new location is found.</p>
  
  <p>Thanks to the log I know the service is working and I have new locations every seconds or so, but I never get the broadcast.</p>
  
  <p>MainActivity.java</p>
  
  <pre><code>public class MainActivity extends Activity {
  
  
  private static final String TAG = "mainActivity";
  
  private CMBroadcastReceiver mMessageReceiver = new CMBroadcastReceiver();
  
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
  
      // Start Service
      startService(new Intent(this, LocationService.class));
  
      super.onCreate(savedInstanceState);
  }
  
  @Override
  public void onResume()
  {
      LocalBroadcastManager.getInstance(this).registerReceiver(
              mMessageReceiver, new IntentFilter(CMBroadcastReceiver.RECEIVE_LOCATION_UPDATE));
      super.onResume();
  }
  
  @Override
  public void onPause()
  {
      LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver);
      super.onPause();
  }
  }
  </code></pre>
  
  <p>CMBroadcastReceiver.java</p>
  
  <pre><code>public class CMBroadcastReceiver extends BroadcastReceiver {
  
  private static final String TAG = "CMBroadcastReceiver";
  
  public static final String RECEIVE_LOCATION_UPDATE = "LOCATION_UPDATES";
  
  @Override
  public void onReceive(Context context, Intent intent) {
      Log.i(TAG, "Received broadcast");
      String action = intent.getAction();
      if (action.equals(RECEIVE_LOCATION_UPDATE))
      {
          Log.i(TAG, "Received location update from service!");
      }
  }
  }
  </code></pre>
  
  <p>LocationService.java</p>
  
  <pre><code>/**
   * Callback that fires when the location changes.
   */
  @Override
  public void onLocationChanged(Location location) {
      mCurrentLocation = location;
      mLastUpdateTime = DateFormat.getTimeInstance().format(new Date());
      Log.i(TAG, "onLocationChanged " + location);
  
      Intent intent = new Intent(CMBroadcastReceiver.RECEIVE_LOCATION_UPDATE);
      LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
      Log.i(TAG, "Broadcast sent");
  }
  </code></pre>
  
  <p>AndroidManifest.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.cyclemapapp.gpstracker"&gt;
  
  &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/&gt;
  &lt;application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:supportsRtl="true"
      android:theme="@style/AppTheme"&gt;
      &lt;activity
          android:name=".MainActivity"
          android:label="@string/title_activity_main"
          android:theme="@style/AppTheme.NoActionBar"&gt;
          android:configChanges="orientation|screenSize"&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;service android:name=".LocationService" android:process=":location_service" /&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p></p>
  
  <p>I the log I can see that "Broadcast Sent" But I never get the "Broadcast Received"</p>
  
  <p>Any help will would be greatly appreciated.</p>
  
  <p><b>EDIT: </b></p>
  
  <p>Edited how the intent was created in the location service as Shaishav suggested.</p>
  
  <p>Still doesn't work.</p>