public final class LocalBroadcastManager
extends Object
java.lang.Object | |
↳ | android.support.v4.content.LocalBroadcastManager |
帮助者注册并发送Intents广播到您的流程中的本地对象。 与使用sendBroadcast(Intent)
发送全球广播相比,这具有许多优势:
Public methods |
|
---|---|
static LocalBroadcastManager |
getInstance(Context context) |
void |
registerReceiver(BroadcastReceiver receiver, IntentFilter filter) 注册接收任何与给定IntentFilter匹配的本地广播。 |
boolean |
sendBroadcast(Intent intent) 将给定的意图广播给所有感兴趣的BroadcastReceivers。 |
void |
sendBroadcastSync(Intent intent) 像 |
void |
unregisterReceiver(BroadcastReceiver receiver) 取消注册以前注册的BroadcastReceiver。 |
Inherited methods |
|
---|---|
From class java.lang.Object
|
LocalBroadcastManager getInstance (Context context)
Parameters | |
---|---|
context |
Context
|
Returns | |
---|---|
LocalBroadcastManager |
void registerReceiver (BroadcastReceiver receiver, IntentFilter filter)
注册接收任何与给定IntentFilter匹配的本地广播。
Parameters | |
---|---|
receiver |
BroadcastReceiver : The BroadcastReceiver to handle the broadcast. |
filter |
IntentFilter : Selects the Intent broadcasts to be received. |
boolean sendBroadcast (Intent intent)
将给定的意图广播给所有感兴趣的BroadcastReceivers。 这个调用是异步的; 它会立即返回,并且您将在接收器运行时继续执行。
Parameters | |
---|---|
intent |
Intent : The Intent to broadcast; all receivers matching this Intent will receive the broadcast. |
Returns | |
---|---|
boolean |
void sendBroadcastSync (Intent intent)
像 sendBroadcast(Intent)
一样,但是如果有任何Intent的接收器,这个函数将会阻塞并在返回之前立即发送它们。
Parameters | |
---|---|
intent |
Intent
|
void unregisterReceiver (BroadcastReceiver receiver)
取消注册以前注册的BroadcastReceiver。 所有为此BroadcastReceiver注册的过滤器都将被删除。
Parameters | |
---|---|
receiver |
BroadcastReceiver : The BroadcastReceiver to unregister. |