Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

differences between different types of broadcasts in android [duplicate]

Tags:

android

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?

like image 769
Nav Avatar asked Mar 31 '12 11:03

Nav


People also ask

What are the different types of broadcast Android?

There are two types of broadcast receivers: Static receivers, which you register in the Android manifest file. Dynamic receivers, which you register using a context.

What is the difference between local normal ordered and sticky broadcasts?

:- normal broadcast intent is not available any more after this was send and processed by the system. :- the corresponding intent is sticky, meaning the intent you are sending stays around after the broadcast is complete.

What is difference between service and broadcast receiver in Android?

A Service receives intents that were sent specifically to your application, just like an Activity. A Broadcast Receiver receives intents that were broadcast system-wide to all apps installed on the device.

Which intent is a broadcast from sendStickyBroadcast?

When you call registerReceiver specifying an Intent Filter that matches a sticky broadcast, the return value will be the sticky broadcast Intent. To broadcast a sticky Intent your application must have the BROADCAST_STICKY uses-permission. sendStickyBroadcast(intent);


1 Answers

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

like image 102
Jens Avatar answered Oct 10 '22 16:10

Jens