What does the sendBroadcast method of the LocalBroadcastManager class return?

Return Value (boolean) LocalBroadcastManager.sendBroadcast () is not documented.

I believe that it returns true when at least one receiver is registered, and false if the receiver is not registered. Is it correct?

There is an open problem with this missing documentation: Issue 59626

+4
source share
1 answer

Yes, it checks for available receivers and returns false if they are not found:

from 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 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;
+3
source

Source: https://habr.com/ru/post/1609894/


All Articles