在Android的 sendStickyBroadcast
和 sendBroadcast
之间的区别是什么?
What is the difference between sendStickyBroadcast
and sendBroadcast
in Android?
推荐答案
Here是Android SDK中说,有关 sendStickyBroadcast()
:
执行sendBroadcast(意向),其 是粘,意思是意向你 在后发周围逗留 播放完毕,让别人 可以快速通过检索数据 的返回值 registerReceiver(BroadcastReceiver的, IntentFilter的)。在所有其他方面,这 的行为一样 sendBroadcast(意向)。
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()
的行动 - 即使有空
的BroadcastReceiver
- 你得到的意图
这是最后一次播出的行动。因此,你可以用它来发现电池的状态,而不必登记在电池的所有未来状态的变化。
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.
相关推荐
最新文章