Two receivers of android LocalBroadcast, one in MainActivity, the other in a fragment
<p>In a android app, I registered a receiver in MainActivity's onCreate</p>

<pre><code>IntentFilter mFilter = new IntentFilter("Action");
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, mFilter);
</code></pre>

<p>In its onResume</p>

<pre><code>new Thread(new Runnable() {
        @Override
        public void run() {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                  Intent i = new Intent("Action");
                  LocalBroadcastManager.getInstance(MainActivity.this).sendBroadcast(i);
                }
            });
        }
    }).start();
</code></pre>

<p>Frankly I am not sure why we wanted to use a thread as such (I copied the code from somewhere w/o fully digesting it). </p>

<p>This app supports ViewPager, thus in its associated Fragment's onCreate</p>

<pre><code>    IntentFilter mFilter = new IntentFilter("Action");
    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mReceiver, mFilter);
</code></pre>

<p>In both MainActivity and Fragment class, the receiver looks like:</p>

<pre><code>    private BroadcastReceiver mReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
         ...
    }
</code></pre>

<p>Only what's inside onReceive differs in both classes.</p>

<p>I don't know too much how LocalBroadcast works, I was expecting both receiver handlers would be run once the a broadcast is emitted. Instead I noticed most time only the receiver in MainActivity runs, occasionally that in the fragment class runs.</p>

<p>My hunch is that there is something to do with the thread part.</p>