广播
来源:互联网 发布:淘宝卖刀具犯法吗 编辑:程序博客网 时间:2024/05/21 07:15
BroadCastReceiver工作过程
广播的使用方法:
1.定义广播接收者(继承BroadCastRecevier)
广播的注册
静态注册
<receiver android:name=".MyReceiver">
<intent-filter>
<action android:name="android.intent.action.MY_BROADCAST"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
动态注册
MyReceiver receiver = new MyReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction("android.intent.action.MY_BROADCAST");
registerReceiver(receiver, filter);
广播的发送与接收
public void send(View view) {
Intent intent = new Intent("android.intent.action.MY_BROADCAST");
intent.putExtra("msg", "hello receiver.");
sendBroadcast(intent);
}
2. 有序广播与普通广播
普通广播(Normal Broadcast)
普通广播对于多个接收者来说是完全异步的,通常每个接收者都无需等待即可以接收到广播,接收者相互之间不会有影响。
对于这种广播,接收者无法终止广播,即无法阻止其他接收者的接收动作。
有序广播(Ordered Broadcast)
有序广播比较特殊,它每次只发送到优先级较高的接收者那里,然后由优先级高的接受者再传播到优先级低的接收者那里,优先级高的接收者有能力终止这个广播。
广播的使用方法:
1.定义广播接收者(继承BroadCastRecevier)
广播的注册
静态注册
<receiver android:name=".MyReceiver">
<intent-filter>
<action android:name="android.intent.action.MY_BROADCAST"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
动态注册
MyReceiver receiver = new MyReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction("android.intent.action.MY_BROADCAST");
registerReceiver(receiver, filter);
广播的发送与接收
public void send(View view) {
Intent intent = new Intent("android.intent.action.MY_BROADCAST");
intent.putExtra("msg", "hello receiver.");
sendBroadcast(intent);
}
2. 有序广播与普通广播
普通广播(Normal Broadcast)
普通广播对于多个接收者来说是完全异步的,通常每个接收者都无需等待即可以接收到广播,接收者相互之间不会有影响。
对于这种广播,接收者无法终止广播,即无法阻止其他接收者的接收动作。
有序广播(Ordered Broadcast)
有序广播比较特殊,它每次只发送到优先级较高的接收者那里,然后由优先级高的接受者再传播到优先级低的接收者那里,优先级高的接收者有能力终止这个广播。
3.电量变化、网络状态变化等使用广播
ContentProvider
ActivityThread先加载contentprovider,再调用Application的oncreate方法
UriMather
getType
阅读全文
0 0
- 广播
- 广播
- 广播
- 广播
- 广播
- 广播
- 广播
- 广播
- 广播
- 广播:
- 广播
- 广播
- 广播
- 广播
- 广播
- 广播
- 广播
- 广播
- 剑指offer——左旋转字符串
- 部分背包问题
- jvm原理讲解和调优
- mysql相关函数
- 在win7x64系统中安装snmp
- 广播
- Cocos2d-x 3.X下Lua调用自定义C++类和函数的最佳实践
- 编程规范
- 字符串非数字替换 C QString方式
- 在Ubuntu下qt creator 在C++的多线程
- UserWarning: The installed version of numexpr 2.4 is not supported in pandas and will be not be used
- (lintcode)第4题 丑数II
- Xcode8出现AQDefaultDevice(173):Skipping input stram 0 0 0x0
- 剑指Offer—31—整数中1出现的次数(从1到n整数中1出现的次数)