Share via


RemoteCallbackList.BeginBroadcast Method

Definition

Use #broadcast(Consumer) instead to ensure proper handling of frozen processes.

[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 interfaces in the broadcast, to be used with #getBroadcastItem to determine the range of indices you can supply.

Attributes

Remarks

Use #broadcast(Consumer) instead to ensure proper handling of frozen processes.

Prepare to start making calls to the currently registered interfaces. This creates a copy of the interface 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 = interfaces.beginBroadcast();
            while (i &gt; 0) {
                i--;
                try {
                    interfaces.getBroadcastItem(i).somethingHappened();
                } catch (RemoteException e) {
                    // The RemoteCallbackList will take care of removing
                    // the dead object for us.
                }
            }
            interfaces.finishBroadcast();

Note that this method is only supported for #FROZEN_CALLEE_POLICY_UNSET. For other policies use #broadcast(Consumer) instead.

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