赞
踩
BroadcastReceiver就是一个广播消息接收者。
广播之间信息的传递是通过Intent对象来传递的。
首先构造一个接收器:
广播的传递是靠Intent的,OnReceive的第二个参数,就是广播传过来的Intent。
MyReceiver的广播接收 注册代码如下:(静态注册)
intent-filter标签里,同样是必须的两项:action和category;我在这里自定义了action的名字,等下隐式发送通过时,就是利用匹配action来接收通知的。
这里特别注意<activity> 标签与<receiver>标签的构造。完全相同!!!!!!!
完全相同体现在:
最后是发送广播:
我们在主页面加一个Button,当点击Button时发送广播消息。
布局文件如下:(activity_main.xml)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。