I came across this term in the android documentation with the accompanying definition
These are broadcasts whose data is held by the system after being finished, so that clients can quickly retrieve that data without having to wait for the next broadcast.
What does it mean? Can someone elaborate its use with a particular example? I believe we have to request a permission for using this intent? Why so?
<uses-permission android:name="android.permission.BROADCAST_STICKY"/> - Allows an application to broadcast sticky intents.
A Sticky Broadcast is a Broadcast that stays around following the moment it is announced to the system. Most Broadcasts are sent, processed within the system and become quickly inaccessible. However, Sticky Broadcasts announce information that remains accessible beyond the point at which they are processed.
A sticky broadcast is a tool Android developers use for communicating between apps. These broadcasts happen without the user being notified. The Android OS normally treats each application as if it were a separate user.
Sticky broadcasts stick around even after your app is gone. The only reliable way to get rid of them is through phone restart.
Sticky Intent is also a type of Intent which allows communication between a function and a service sendStickyBroadcast(), performs a sendBroadcast(Intent) known as sticky, the Intent you are sending stays around after the broadcast is complete, so that others can quickly retrieve that data through the return value of ...
If an Activity calls onPause
with a normal broadcast, receiving the Broadcast can be missed. A sticky broadcast can be checked after it was initiated in onResume
.
Sticky broadcasts are deprecated.
See sendStickyBroadcast
documentation.
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.
Intent intent = new Intent("some.custom.action"); intent.putExtra("some_boolean", true); sendStickyBroadcast(intent);
Related post: What is the difference between sendStickyBroadcast and sendBroadcast in Android?
See removeStickyBroadcast(Intent)
, and on API Level 5 +, isInitialStickyBroadcast()
for usage in the Receiver's onReceive
.
sendStickyBroadcast()
performs a sendBroadcast(Intent)
known as sticky, i.e. the Intent you are sending stays around after the broadcast is complete, so that others can quickly retrieve that data through the return value of registerReceiver(BroadcastReceiver, IntentFilter)
. In all other ways, this behaves the same as sendBroadcast(Intent)
. One example of a sticky broadcast sent via the operating system is ACTION_BATTERY_CHANGED
. When you call registerReceiver()
for that action -- even with a null BroadcastReceiver
-- you get the Intent that was last broadcast for that action. Hence, you can use this to find the state of the battery without necessarily registering for all future state changes in the battery.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With