RemoteCallbackList.BeginBroadcast Method

Definition

Prepare to start making calls to the currently registered callbacks.

[Android.Runtime.Register("beginBroadcast", "()I", "GetBeginBroadcastHandler")]
public virtual int BeginBroadcast ();
[<Android.Runtime.Register("beginBroadcast", "()I", "GetBeginBroadcastHandler")>]
abstract member BeginBroadcast : unit -> int
override this.BeginBroadcast : unit -> int

Returns

Returns the number of callbacks in the broadcast, to be used with #getBroadcastItem to determine the range of indices you can supply.

Attributes

Remarks

Prepare to start making calls to the currently registered callbacks. This creates a copy of the callback list, which you can retrieve items from using #getBroadcastItem. Note that only one broadcast can be active at a time, so you must be sure to always call this from the same thread (usually by scheduling with Handler) or do your own synchronization. You must call #finishBroadcast when done.

A typical loop delivering a broadcast looks like this:

int i = callbacks.beginBroadcast();
            while (i &gt; 0) {
                i--;
                try {
                    callbacks.getBroadcastItem(i).somethingHappened();
                } catch (RemoteException e) {
                    // The RemoteCallbackList will take care of removing
                    // the dead object for us.
                }
            }
            callbacks.finishBroadcast();

Java documentation for android.os.RemoteCallbackList.beginBroadcast().

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

See also