RemoteCallbackList.Builder


public static final class RemoteCallbackList.Builder
extends Object

java.lang.Object
   ↳ android.os.RemoteCallbackList.Builder<E extends android.os.IInterface>


Builder for RemoteCallbackList.

Summary

Nested classes

interface RemoteCallbackList.Builder.InterfaceDiedCallback<E extends IInterface>

For notifying when the process hosting a callback interface has died. 

Public constructors

Builder(int frozenCalleePolicy)

Creates a Builder for RemoteCallbackList.

Public methods

RemoteCallbackList<E> build()

Builds and returns a RemoteCallbackList.

RemoteCallbackList.Builder<E> setExecutor(Executor executor)

Sets the executor to be used when invoking callbacks asynchronously.

RemoteCallbackList.Builder<E> setInterfaceDiedCallback(InterfaceDiedCallback<E> callback)

Sets the callback to be invoked when an interface dies.

RemoteCallbackList.Builder<E> setMaxQueueSize(int maxQueueSize)

Sets the max queue size.

Inherited methods

Public constructors

Builder

public Builder (int frozenCalleePolicy)

Creates a Builder for RemoteCallbackList.

Parameters
frozenCalleePolicy int: When the callback recipient's process is frozen, this parameter specifies when/whether callbacks are invoked. It's important to choose a strategy that's right for the use case. Leaving the policy unset with RemoteCallbackList.FROZEN_CALLEE_POLICY_UNSET is not recommended as it allows callbacks to be invoked while the recipient is frozen. Value is RemoteCallbackList.FROZEN_CALLEE_POLICY_UNSET, RemoteCallbackList.FROZEN_CALLEE_POLICY_ENQUEUE_ALL, RemoteCallbackList.FROZEN_CALLEE_POLICY_ENQUEUE_MOST_RECENT, or RemoteCallbackList.FROZEN_CALLEE_POLICY_DROP

Public methods

build

public RemoteCallbackList<E> build ()

Builds and returns a RemoteCallbackList.

Returns
RemoteCallbackList<E> The built RemoteCallbackList object. This value cannot be null.

setExecutor

public RemoteCallbackList.Builder<E> setExecutor (Executor executor)

Sets the executor to be used when invoking callbacks asynchronously. This is only used when callbacks need to be invoked asynchronously, e.g. when the process hosting a callback becomes unfrozen. Callbacks that can be invoked immediately run on the same thread that calls RemoteCallbackList.broadcast(Consumer) synchronously.

Parameters
executor Executor: This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.

Returns
RemoteCallbackList.Builder<E> This value cannot be null.

setInterfaceDiedCallback

public RemoteCallbackList.Builder<E> setInterfaceDiedCallback (InterfaceDiedCallback<E> callback)

Sets the callback to be invoked when an interface dies.

Parameters
callback InterfaceDiedCallback: This value cannot be null.

Returns
RemoteCallbackList.Builder<E> This value cannot be null.

setMaxQueueSize

public RemoteCallbackList.Builder<E> setMaxQueueSize (int maxQueueSize)

Sets the max queue size.

Parameters
maxQueueSize int: The max size limit on the queue that stores callbacks added when the recipient's process is frozen. Once the limit is reached, the oldest callback is dropped to keep the size under the limit. Should only be called for RemoteCallbackList.FROZEN_CALLEE_POLICY_ENQUEUE_ALL.

Returns
RemoteCallbackList.Builder<E> This builder. This value cannot be null.

Throws
IllegalArgumentException if the maxQueueSize is not positive.
UnsupportedOperationException if frozenCalleePolicy is not RemoteCallbackList.FROZEN_CALLEE_POLICY_ENQUEUE_ALL.