Android LocalBroadcastManager from Fragment to Activity not receiving message
<p>I want to sent a message from a <code>Fragment</code> to an <code>Activity</code> (not the <code>Fragment</code> parent <code>Activity</code>, just another one).</p>

<p>Actually I do the same from a <code>Service</code> to the same <code>Activity</code> and it works great.</p>

<p>This is my code:</p>

<p><code>Fragment</code>:</p>

<pre><code>private void sendBroadcastMessage() {
    Intent intent = new Intent("my_event");
    // add data
    intent.putExtra("message", "test");
    LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(intent);
}
</code></pre>

<p><code>Activity</code>:</p>

<pre><code>private BroadcastReceiver myReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        // Extract data included in the Intent
        String message = intent.getStringExtra("message");

    }
};

@Override
protected void onPause() {
    // Unregister since the activity is not visible 
    LocalBroadcastManager.getInstance(this).unregisterReceiver(myReceiver);
    super.onPause();
}

@Override
protected void onResume() {
    super.onResume();    LocalBroadcastManager.getInstance(this).registerReceiver(myReceiver, new IntentFilter("my_event"));
}
</code></pre>

<p>I've just followed that great <a href="https://stackoverflow.com/a/25172526/2274847">post</a>, but it only works from <code>Service</code> to <code>Activity</code></p>

<p>I think it has something to do with the <code>Context</code> from the <code>Fragment</code>, maybe <code>getActivity()</code> is not the right way...</p>

<p>Any ideas?
Thanks.</p>