都是为了获得Android的广播?都是、Android

2023-09-06 02:01:33 作者:曾经一身傲气

如果2广播,A和B,并将其发送的顺序,确实安卓保证所有感兴趣的接收器将接收它们以同样的顺序?

If 2 broadcasts, A and B, and sent in that order, does Android guarantee that all interested receivers will receive them in the same order?

推荐答案

我相信你是问,如果有任何的方式来保证每个有兴趣的接收器将获得广播B.我能给出的最好的答案之前接收其各自的广播A是,它是非常有可能的,因为所有的节目都传递给 ActivityManager 应处理它们反过来。但我不相信这是在保证这种行为(我找不到ActivityManager队列,他们都张贴或类似的东西)的框架,任何东西。此外,的BroadcastReceiver 将只在一个时间,这有助于处理一个意图。

I believe you are asking if there is any way to guarantee that each interested receiver will receive its respective Broadcast A before getting Broadcast B. The best answer I can give is that it is highly likely, because all broadcasts are passed to the ActivityManager which should handle them in turn. But I don't believe there is anything in the framework that "guarantees" this behavior (I can't find a queue on ActivityManager where they are all posted or anything like that). Also, BroadcastReceiver will only handle one Intent at a time, which helps.

相反,如果你的意思是我能控制的,其中每个广播发送接收机的秩序,那么你的答案在于 sendOrderedBroadcast()其他已躲避到。

If instead you meant "can I control the order of receivers in which each broadcast is sent", then your answer lies with sendOrderedBroadcast() as other have eluded to.