android BroadcastReceiver概要

BroadcastReceiver相信每个android开发者都是接触过的,今天不讲它的用法,而是说说有序广播与无序广播的特点

在多数代码中我们经常会看到sendBroadcast(),使用这样的方式都是发送一份无序广播,而使用sendOrderedBroadcast()则是发送一份有序广播,而接收广播的先后顺序在BroadcastReceiver中的intent-filter中配置prioity的值,这个值越大,接收广播的优先级越高。

在判断一个广播是不是有序广播的简单方式就是通过abortBroadcast()方法判断,如果此广播被终止了,则说明则广播为有序广播,因为无序广播是无法终止的。


在这里还简单说一个方法:

public abstract void sendOrderedBroadcast (Intent intent, String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras)

ntentThe Intent to broadcast; all receivers matching this Intent will receive the broadcast.
receiverPermissionString naming a permissions that a receiver must hold in order to receive your broadcast. If null, no permission is required.
resultReceiverYour own BroadcastReceiver to treat as the final receiver of the broadcast.
schedulerA custom Handler with which to schedule the resultReceiver callback; if null it will be scheduled in the Context's main thread.
initialCodeAn initial value for the result code. Often Activity.RESULT_OK.
initialDataAn initial value for the result data. Often null.
initialExtrasAn initial value for the result extras. Often null.




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值