广播是应用于系统、应用、控件、线程间消息响应的组件分为无序广播,有序广播,粘性广播
静态注册{
![](https://i-blog.csdnimg.cn/blog_migrate/73f80c214063da7f8f6b3214248d2831.png)
![](https://i-blog.csdnimg.cn/blog_migrate/333b435ed8b12d408784113a7b8e8f44.png)
Intent intent = new Intent();
intent.setAction("com.bw.yan");
sendBroadcast(intent);
![](https://i-blog.csdnimg.cn/blog_migrate/94015d3954ca80c1337af7f1f6b89fac.png)
}
动态注册{
继承BroadcastReceiver重写onReceove方法
![](https://i-blog.csdnimg.cn/blog_migrate/6aa2b4cb9949bff6eb6a0e39c6e3ad63.png)
myDynReceiver = new MyDynReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("com.bw.yjh");
registerReceiver(myDynReceiver,intentFilter);
Intent intent = new Intent();
intent.setAction("com.bw.yjh");
sendBroadcast(intent);
}
粘性广播{
创建Fragment
Intent intent = new Intent();
intent.setAction("bw.aa");
sendStickyBroadcast(intent);
}
有序广播{
设置receiver至少两个
//有序广播
oneReceiver = new OneReceiver();
intentFilter.addAction("com.bw.kf");
//设置优先—— 数字越高越先输出
intentFilter.setPriority(50);
registerReceiver(oneReceiver,intentFilter);
twoReceiver = new TwoReceiver();
intentFilter.addAction("com.bw.kf");
//设置优先
intentFilter.setPriority(100);
registerReceiver(twoReceiver,intentFilter);
Intent intent = new Intent();
intent.setAction("com.bw.kf");
sendOrderedBroadcast(intent,null);
![](https://i-blog.csdnimg.cn/blog_migrate/7a6e2a01b96df3fa77cc8c9645c6c546.png)
}
app之间发送广播{
app之间发送广播用到粘性广播
![](https://i-blog.csdnimg.cn/blog_migrate/e6b5d2a1f206782a5bb65825cc5f1816.png)
Intent intent = new Intent();
intent.setAction("com.bw.app");
sendStickyBroadcast(intent);
接受广播app中的内容
![](https://i-blog.csdnimg.cn/blog_migrate/63a795d7cab9fa506fe7794f79c02547.png)
![](https://i-blog.csdnimg.cn/blog_migrate/f923f0bf0deb91b55a6ab6cad29722db.png)
}