20

I am a little confused with the documentation regarding the different types of sending broadcasts in Android. For example, there is sendStickyBroadcast(), sendBroadcast(), sendOrderedBroadcast() and sendStickyOrderedBroadcast().

What is the difference between a sticky, normal and ordered broadcast?

spaaarky21
  • 6,524
  • 7
  • 52
  • 65
Nav
  • 10,304
  • 20
  • 56
  • 83

1 Answers1

59

You can compare a sticky broadcast with a sticky note. Someone posts it and you can read when you pass by/your application starts - regardless of when it was posted.

An ordered broadcast is like passing a note - it passes from person/application to person/application. Anywhere in the chain the recipient can elect to cancel the broadcast preventing the rest of the chain from seeing it.

A normal broadcast.. well, just sends to everyone that's allowed & registered to listen to it.

There's a variation of broadcasts that only allow receivers registered in a running application to listen to them - i.e. a receiver in your AndroidManifest.xml will not trigger for these Intents.

An update regarding sendStickyBroadcast:

This method was deprecated in API level 21. Sticky broadcasts should not be used. They provide no security (anyone can access them), no protection (anyone can modify them), and many other problems. The recommended pattern is to use a non-sticky broadcast to report that something has changed, with another mechanism for apps to retrieve the current value whenever desired.

Source

Mudassir
  • 13,031
  • 8
  • 59
  • 87
Jens
  • 16,853
  • 4
  • 55
  • 52