12

Is this possible to check if a broadcast was sent in sticky mode?

Can we completely abort/remove a sticky broadcast? If yes, then can it be done for both normal and ordered broadcasts?

blackfyre
  • 2,549
  • 5
  • 39
  • 58
  • 2
    Sticky broadcasts can be removed; see .... http://stackoverflow.com/questions/11839043/android-how-can-i-completely-abort-remove-sticky-broadcast –  Aug 15 '12 at 08:33

1 Answers1

24

In onReceive() you can use the following calls:

isInitialStickyBroadcast() - This will tell you if the broadcast you are currently processing was sent as "sticky" and was the current one when the BroadcastReceiver was registered.

isOrderedBroadcast() - This will tell you if the broadcast you are currently processing was sent as an "ordered" broadcast.

If you just want to see if there is a "sticky" broadcast, you can call

registerReceiver (BroadcastReceiver receiver, IntentFilter filter)

and supply null as the receiver parameter. This will return any "sticky" broadcast without actually registering the receiver.

You can remove a sticky broadcast using:

removeStickyBroadcast(Intent intent)

However, IMHO that would be counter-productive. Usually "sticky" broadcasts are sent to indicate the current state of something. So removing it would imply that it isn't possible for an application to determine the current state.

David Wasser
  • 93,459
  • 16
  • 209
  • 274