Reputation: 700
I want to send simple sata from an activity to another. Both are active at the time and I have registered LocalBroadcastManager. the sending part work but the receiving activity doesn't get anything. BroadcastManager sending data part of the code :
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
LocalBroadcastManager broadcaster = LocalBroadcastManager.getInstance(SendingDataPageActivity.this);
Intent broadcastIntent = new Intent(BROADCAST_INTENT);
broadcastIntent.putExtra("test, "test");
broadcastIntent.setAction("test, "test");
broadcaster.sendBroadcast(broadcastIntent);
Log.d(TAG, "Broadcast sent..."); });
And For receiver:
public class RecievingDataPageActivity extends AppCompatActivity{
BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "local broadcaster received...");}};
I have registered it in OnCreate:
LocalBroadcastManager.getInstance(this).registerReceiver((receiver),
new IntentFilter(BROADCAST_INTENT));
But still doesn't receive anything. Any help?
Upvotes: 0
Views: 354
Reputation: 3389
You are setting your action in the Intent constructor:
Intent broadcastIntent = new Intent(BROADCAST_INTENT);
But 2 lines after, you are overriding it:
broadcastIntent.setAction("test", "test");
You can only have one action so Intent gets lost.
Upvotes: 1
Reputation: 1
Remove this line and try again.
broadcastIntent.setAction("test, "test");
Upvotes: 0