What is the difference between sendStickyBroadcast
and sendBroadcast
in Android?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
Here is what the Android SDK says about
sendStickyBroadcast()
:One example of a sticky broadcast sent via the operating system is
ACTION_BATTERY_CHANGED
. When you callregisterReceiver()
for that action -- even with anull
BroadcastReceiver
-- you get theIntent
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.sendbroadcast()
- normal broadcast, but we can set priority as well.sendstickybroadcast()
- intent passed with this will be stick for future users who are registering through code (dynamic receivers). The broadcast that will stick with android, and will be re-delivered or re-broadcasted to the future requests from any broadcast receiversWhen somebody sends a sticky broadcast using
sendstickyBroadcast(intent);
then that broadcast will be available for the future users who are using dynamic receivers.But Now you should not use
sendStickyBroadcast()
method it is deprecatedFrom Android Documentation:
I hope this helps.
Types :- Local,Normal,Ordered and Sticky
Normal Broadcast
:- use sendBroadcast()
:- asynchronous broadcast
:- any receiver receives broadcast not any particular order
Ordered Broadcast
:- use sendOrderedBroadcast()
:- synchronous broadcast
:- receiver receives broadcast in priority base
:- we can also simply abort broadcast in this type
Local Broadcast
:- use only when broadcast is used only inside same process
Sticky Broadcast
:- normal broadcast intent is not available any more after this was send and processed by the system.
:- use sendStickyBroadcast(Intent)
:- the corresponding intent is sticky, meaning the intent you are sending stays around after the broadcast is complete.
:- because of this others can quickly retrieve that data through the return value of registerReceiver(BroadcastReceiver, IntentFilter).
:- apart from this same as sendBroadcast(Intent).