有序广播
1.注册多个receiver,要同时使用同一个action,设置priority来指定优先级。

2.发送有序广播:sendOrderedBroadcast(intent,null);
Intent intent = new Intent("www.wangpeng");
intent.putExtra("name","我是有序排序");
sendOrderedBroadcast(intent,null);
三个接收类:
常用方法:
1.setResultExtras(Bundle 对象)设置携带数据
2.getResultExtras(true)获取携带数据,得到的是Bundle对象
3.abortBroadcast() 中止广播
String name = intent.getStringExtra("name");
Bundle bundle = new Bundle();
bundle.putString("xiedai","我是携带数据");
setResultExtras(bundle);
Log.d("###","我是接受方一:"+name);
String name = intent.getStringExtra("name");
Log.d("###","我是接受方2:"+name);
Bundle resultExtras = getResultExtras(true);
String xiedai = resultExtras.getString("xiedai");
Log.d("###","携带数据2:"+xiedai);
String name = intent.getStringExtra("name");
Bundle resultExtras = getResultExtras(true);
String xiedai = resultExtras.getString("xiedai");
Log.d("###","我是接受方3:"+name);
Log.d("###","携带数据3:"+xiedai);
效果:

粘性广播
特点:可以不用先执行注册方(延时收广播)
方法: sendStickyBroadcast(intent 对象)
发送方:

动态注册:

博客介绍了有序广播和粘性广播。有序广播需注册多个receiver,用同一action并设置priority指定优先级,通过sendOrderedBroadcast发送,还有设置、获取携带数据及中止广播等常用方法;粘性广播特点是可延时收广播,用sendStickyBroadcast发送。
541

被折叠的 条评论
为什么被折叠?



