广播

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)
  有序广播比较特殊,它每次只发送到优先级较高的接收者那里,然后由优先级高的接受者再传播到优先级低的接收者那里,优先级高的接收者有能力终止这个广播。
  
  

3.电量变化、网络状态变化等使用广播





ContentProvider
ActivityThread先加载contentprovider,再调用Application的oncreate方法
UriMather
getType

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值