什么是持久广播?持久

由网友(撞上小白兔)分享简介:我在Android文档中碰到这个词与随附定义这些是广播其数据由系统保持被完成之后,以便客户端可以快速地检索的数据,而不必等待下一个广播。 这是什么意思?有人能阐述其与特定的例子用?我相信我们有请求准许使用此意图是什么?为什么会这样?<使用-权限的Andr​​oid:名称=android.permission.BR...

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

  

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

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

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

解决方案 广播站 我们等你很久了

请阅读马克·墨菲的解释在这里: what是sendStickyBroadcast和sendBroadcast Android中的区别

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

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

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

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

另外,请查阅removeStickyBroadcast(Intent),和API级别5 +,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.

阅读全文

相关推荐

最新文章