什么是持久广播? [英] What is a Sticky Broadcast?

查看:487
本文介绍了什么是持久广播?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android文档中碰到这个词与随附定义

  

这些是广播其数据由系统保持被完成之后,以便客户端可以快速地检索的数据,而不必等待下一个广播。

这是什么意思?有人能阐述其与特定的例子用?我相信我们有请求准许使用此意图是什么?为什么会这样?

 <使用-权限的Andr​​oid:名称=android.permission.BROADCAST_STICKY/> - 允许应用程序广播常用意图。
 

解决方案

请阅读马克·墨菲的解释在这里: <一href="http://stackoverflow.com/questions/2584497/what-is-the-difference-between-sendstickybroadcast-and-sendbroadcast-in-android">what是sendStickyBroadcast和sendBroadcast Android中的区别

下面是怎么一会用持久广播一个抽象的例子:

 意向意图=新的意图(some.custom.action);
intent.putExtra(some_boolean,真正的);
sendStickyBroadcast(意向);
 

如果您正在收听此广播中被冻结的活动(的onPause),你可能会错过实际事件。这可以让你检查广播它被解雇后(onResume)。

编辑:更多关于持久广播...

另外,请查阅<一个href="http://developer.android.com/reference/android/content/Context.html#removeStickyBroadcast%28android.content.Intent%29"><$c$c>removeStickyBroadcast(Intent),和API级别5 +,<一个href="http://developer.android.com/reference/android/content/BroadcastReceiver.html#isInitialStickyBroadcast%28%29"><$c$c>isInitialStickyBroadcast()对于使用在接收器的的onReceive

希望有所帮助。

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.

解决方案

Please read Mark Murphy's explanation here: what is the difference between sendStickyBroadcast and sendBroadcast in Android

Here's an abstract example of how one might use a sticky broadcast:

Intent intent = new Intent("some.custom.action");
intent.putExtra("some_boolean", true);
sendStickyBroadcast(intent);

If you are listening for this broadcast in an Activity that was frozen (onPause), you could miss the actual event. This allows you to check the broadcast after it was fired (onResume).

EDIT: More on sticky broadcasts...

Also check out removeStickyBroadcast(Intent), and on API Level 5 +, isInitialStickyBroadcast() for usage in the Receiver's onReceive.

Hope that helps.

这篇关于什么是持久广播?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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