LocalBroadcastManager属于v4包里面的类。
android.support.v4.content.LocalBroadcastManager
developer里面OverView是这么写的:
Helper to register for and send broadcasts of intents to local objects within your peocess.this is has a number of advantages over sending global broadcasts with sendBroadcast(Intent):
.You know that the data you are braodcasting 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 effcient than sending a global broadcast through the system.
通过粗体部分能看出来这是一个在你app内部通信的方法,在app内部通信上和全局的boradcast相比有优势。体现为:
1.因为是内部通信不会离开该app,所以不用担心数据泄露出去。
2.比全局boradcast更有效率.
3.内部方法不用担心安全问题.
使用也很简单:
LocalBroadCastManager.getInstance(context).registerReceiver(receiver,intentfilter);
LocalBroadCastManager.getInstance(context).sendBroadcast(Intent);
LocalBroadCastManager.getInstance(context).unregisterReiver(receiver);