21

I am interested in using pending intents with local broadcasts. To make myself clear, I am using the following for registering receivers and sending broadcast: android.support.v4.content.LocalBroadcastManager.

I have a local broadcast receiver in a service which works. I am trying to send local broadcasts from a custom notification layout which includes click-able items.

The local broadcast receiver - just receives simple action intents. I was trying something like this to no avail:

Intent backintent = new Intent("GOTO_START_BROADCAST");
PendingIntent backIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, backintent, 0);
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification);
contentView.setOnClickPendingIntent(R.id.imageView1, backIntent);
Nims
  • 477
  • 1
  • 5
  • 12

1 Answers1

29

I am interested in using pending intents with local broadcasts.

That is not possible.

The point behind a PendingIntent is to allow some other process to perform an action you request, such as sending a broadcast.

The point behind LocalBroadcastManager is to keep broadcast within your process.

Hence, a PendingIntent can issue a regular broadcast, but not one via LocalBroadcastManager.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • is there a way for me to have a facility like `PendingIntent.UPDATE_CURRENT` etc., using `LocalBroadcastManager`? Basically when there is a lot of events happening at once, I would like to send just one `LocalBroadcast` instead of one for each event. How would I accomplish that using a `LocalBroadcast`. – 500865 Nov 21 '13 at 20:02
  • 3
    @500865: `PendingIntent` cannot work with `LocalBroadcastManager`. A `PendingIntent` is designed to work across process boundaries; `LocalBroadcastManager` is designed to *not* work across process boundaries. – CommonsWare Nov 21 '13 at 20:13
  • This is why my `BroadcastReceiver` wasn't receiving broadcasts. Solved by using the conventional `BroadcastManager`. – AxeEffect Dec 09 '14 at 09:18