Android 中的 sendStickyBroadcast 和 sendBroadcast 有什么区别 [英] what is the difference between sendStickyBroadcast and sendBroadcast in Android

查看:46
本文介绍了Android 中的 sendStickyBroadcast 和 sendBroadcast 有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

sendStickyBroadcastsendBroadcast 在 Android 中有什么区别?

What is the difference between sendStickyBroadcast and sendBroadcast in Android?

推荐答案

以下是 Android SDK 关于 sendStickyBroadcast() 的说明:

执行一个 sendBroadcast(Intent)是粘性的",意思是你的意图发送住宿后广播完成,让其他人可以通过以下方式快速检索该数据的返回值注册接收器(广播接收器,意图过滤器).在所有其他方面,这行为与发送广播(意图).

Perform a sendBroadcast(Intent) that is "sticky," meaning 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).

通过操作系统发送的粘性广播的一个示例是 ACTION_BATTERY_CHANGED.当您为该操作调用 registerReceiver() 时 - 即使使用 null BroadcastReceiver - 您也会获得 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.

这篇关于Android 中的 sendStickyBroadcast 和 sendBroadcast 有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆