Can you use pending intents with localbroadcasts?

╄→гoц情女王★ 提交于 2019-12-21 07:28:49

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/15790734/can-you-use-pending-intents-with-localbroadcasts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!