gpt4 book ai didi

android - LocalBroadcastManager 类的 sendBroadcast 方法返回什么?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:22:21 26 4
gpt4 key购买 nike

LocalBroadcastManager.sendBroadcast() 的返回值( bool 值)没有记录。

我想当至少有一个接收者被注册时它返回 true,如果没有接收者被注册则返回 false。这是正确的吗?

关于此缺失文档存在未决问题:Issue 59626

最佳答案

是的,它会检查可用的接收器,如果没有找到则返回 false:

来自 method

219                ArrayList<ReceiverRecord> receivers = null;
220 for (int i=0; i<entries.size(); i++) {
221 ReceiverRecord receiver = entries.get(i);
222 if (debug) Log.v(TAG, "Matching against filter " + receiver.filter);
223
224 if (receiver.broadcasting) {
225 if (debug) {
226 Log.v(TAG, " Filter's target already added");
227 }
228 continue;
229 }
230
231 int match = receiver.filter.match(action, type, scheme, data,
232 categories, "LocalBroadcastManager");
233 if (match >= 0) {
234 if (debug) Log.v(TAG, " Filter matched! match=0x" +
235 Integer.toHexString(match));
236 if (receivers == null) {
237 receivers = new ArrayList<ReceiverRecord>();
238 }
239 receivers.add(receiver);
240 receiver.broadcasting = true;
241 } else {
242 if (debug) {
243 String reason;
244 switch (match) {
245 case IntentFilter.NO_MATCH_ACTION: reason = "action"; break;
246 case IntentFilter.NO_MATCH_CATEGORY: reason = "category"; break;
247 case IntentFilter.NO_MATCH_DATA: reason = "data"; break;
248 case IntentFilter.NO_MATCH_TYPE: reason = "type"; break;
249 default: reason = "unknown reason"; break;
250 }
251 Log.v(TAG, " Filter did not match: " + reason);
252 }
253 }
254 }
255
256 if (receivers != null) {
257 for (int i=0; i<receivers.size(); i++) {
258 receivers.get(i).broadcasting = false;
259 }
260 mPendingBroadcasts.add(new BroadcastRecord(intent, receivers));
261 if (!mHandler.hasMessages(MSG_EXEC_PENDING_BROADCASTS)) {
262 mHandler.sendEmptyMessage(MSG_EXEC_PENDING_BROADCASTS);
263 }
264 return true;
265 }
266 }
267 }
268 return false;

关于android - LocalBroadcastManager 类的 sendBroadcast 方法返回什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32901172/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com