action名称一样的广播接收器都有权力接收到广播。但是其中优先级高的会先接收到广播。如果发送的广播属于有序广播( sendOrderedBroadcast() ),而不是无需广播( sendBroadcast() ),那么优先级高的接收器可以利用abortBroadcast()防止广播继续向同类广播接收器传播。
<receiver
android:name = ".MyReceiver">
<intent-filter
android:priority="9">
<action android:name = "包名.intent.action.Receiver"/>
</intent-filter>
</receiver>
<receiver
android:name = ".MyReceiver1">
<intent-filter
android:priority="10">
<action android:name = "包名.intent.action.Receiver"/>
</intent-filter>
</receiver>
从上面我们可以看到两个广播接收器的action是一样的,因此我们指定优先级priority。数值越大,优先级越高。因此首先接收到广播的是MyReceiver1。此时如果我们发送的广播属于有序广播( sendOrderedBroadcast() ),便可以在MyReceiver1中使用abortBroadcast()来中断MyReceiver接收广播。