/**
* If set, when sending a broadcast the new broadcast will replace
* any existing pending broadcast that matches it. Matching is defined
* by {@link Intent#filterEquals(Intent) Intent.filterEquals} returning
* true for the intents of the two broadcasts. When a match is found,
* the new broadcast (and receivers associated with it) will replace the
* existing one in the pending broadcast list, remaining at the same
* position in the list.
*
* <p>This flag is most typically used with sticky broadcasts, which
* only care about delivering the most recent values of the broadcast
* to their receivers.
*/
public static final int FLAG_RECEIVER_REPLACE_PENDING = 0x20000000;
前段时间在开发的过程中发现了一个很奇怪的问题, 就是在一个BroadcastReceiver里 接收一个Intent 的消息, 但是并不是这个Intent 的所有消息都可以接收得到。
后来查了一下发送Intent 的地方, 才发现这个Intent 加了一个Flag ,FLAG_RECEIVER_REPLACE_PENDING, 这个flag 将会将之前的Intent 替代掉。加了这个flag,在发送一系列的这样的Intent 之后, 中间有些Intent 有可能在你还没有来得及处理的时候, 就被替代掉了。
另外, 还有一个Flag: FLAG_RECEIVER_REGISTERED_ONLY
如果Intent 加了这个Flag, 那么在Androidmanifest.xml 里定义的Receiver 是接收不到这样的Intent 的。