BroadcastReceiver
目录
- 接收广播
- 动态接收广播
- 静态接收广播
- 发送广播
- 发送标准广播
- 发送有序广播
- 发送本地广播
接收广播
-
动态
- IntentFilter 定义接收广播的类型
- MyBroadcastReceiver extends BroadcastReceiver
- registerBroadcastReceiver(IntentFilter, BroadcastReceiver)
- registerBroadcastReceiver(BroadcastReceiver)
-
静态
- 定义BroadcastReceiver类
- manifest中注册
- 添加IntentFilter
发送广播
- 发送标准广播
Intent intent = new Intent();
intent.setAction("com.example.broadcasttest.MY_BROADCAST");
sendBroadcast(intent);
- 发送有序广播
sendOrderedBroadcast(intent, null);
广播接收器1
<intent-filter android:priority="100">
广播接收器2默认,
则1优先接收到广播
并且1可以截断广播,在onReceiver()方法中使用
abortBroadcast();
- 发送本地广播
new LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
Three passions, simple but overwhelmingly strong, have governed my life: the longing for love, the search for knowledge, and unbearable pity for the suffering of mankind