您的位置:首页 > 移动开发 > Android开发

Android英文文档翻译系列(6)——LocalBroadcastManager

2015-02-28 15:07 267 查看
public class

LocalBroadcastManager

extends Object

java.lang.Object
android.support.v4.content.LocalBroadcastManager

Class Overview

Helper to register for and send broadcasts of Intents to local objects within your process. This is has a number of advantages over sending global broadcasts with
sendBroadcast(Intent)
:

You know that the data you are broadcasting won't leave your app, so don't need to worry about leaking private data.

It is not possible for other applications to send these broadcasts to your app, so you don't need to worry about having security holes they can exploit.

It is more efficient than sending a global broadcast through the system.

Summary

Public Methods
static LocalBroadcastManagergetInstance(Context context)
voidregisterReceiver(BroadcastReceiver receiver, IntentFilter filter)
Register a receive for any local broadcasts that match the given IntentFilter.

booleansendBroadcast(Intent intent)
Broadcast the given intent to all interested BroadcastReceivers.

voidsendBroadcastSync(Intent intent)
Like
sendBroadcast(Intent)
, but if there are any receivers for the Intent this function will block and immediately dispatch them before returning.

voidunregisterReceiver(BroadcastReceiver receiver)
Unregister a previously registered BroadcastReceiver.

[Expand]
Inherited Methods



From class java.lang.Object

Public Methods

public static LocalBroadcastManager getInstance (Context context)

public void registerReceiver (BroadcastReceiver receiver, IntentFilter filter)

Register a receive for any local broadcasts that match the given IntentFilter.

Parameters
receiverThe BroadcastReceiver to handle the broadcast.
filterSelects the Intent broadcasts to be received.
See Also

unregisterReceiver(BroadcastReceiver)


public boolean sendBroadcast (Intent intent)

Broadcast the given intent to all interested BroadcastReceivers. This call is asynchronous; it returns immediately, and you will continue executing while the receivers are run.

Parameters
intentThe Intent to broadcast; all receivers matching this Intent will receive the broadcast.
See Also

registerReceiver(BroadcastReceiver, IntentFilter)


public void sendBroadcastSync (Intent intent)

Like
sendBroadcast(Intent)
, but if there are any receivers for the Intent this function will block and immediately dispatch them before returning.

public void unregisterReceiver (BroadcastReceiver receiver)

Unregister a previously registered BroadcastReceiver. All filters that have been registered for this BroadcastReceiver will be removed.

Parameters
receiverThe BroadcastReceiver to unregister.
See Also

registerReceiver(BroadcastReceiver, IntentFilter)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: