Reputation: 5480
I send a Broadcast by doing:
Intent intent = new Intent("com.usmaan.myApp.DATA_RECEIVED");
intent.putExtra("matchId", newRowId);
LocalBroadcastManager.getInstance(mContext).sendBroadcast(intent);
This is the Service that wraps up the AsyncTask
which runs Broadcasts the above:
<service
android:name=".services.DataService"
android:exported="false" />
In my Activity, I register a Receiver
in onResume
:
IntentFilter intentFilter = new IntentFilter("com.usmaan.myApp.DATA_RECEIVED");
registerReceiver(mDataReceiver, intentFilter);
The `BroadReceiver looks like this:
private class DataReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
final long matchId = intent.getLongExtra("matchId", 0);
Toast.makeText(LaunchActivity.this, "" + matchId, Toast.LENGTH_LONG);
}
}
The onReceive
is never fired. What am I doing wrong?
Upvotes: 5
Views: 5206
Reputation: 1006614
Either use LocalBroadcastManager
in both places (sendBroadcast()
and registerReceiver()
), or do not use LocalBroadcastManager
at all. Right now, you have a mismatched pair.
Upvotes: 7