Search code examples
androidandroid-broadcastandroid-pendingintent

Can you use pending intents with localbroadcasts?


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);

Solution

  • 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.