SplitControllerCallbackAdapter


@ExperimentalWindowApi
public final class SplitControllerCallbackAdapter


An adapted interface for SplitController that provides callback shaped APIs to report the latest split information with SplitInfo list.

It should only be used if SplitController.splitInfoList is not available. For example, an app is written in Java and cannot use Flow APIs.

Summary

Public constructors

Public methods

final void
addSplitListener(
    @NonNull Activity activity,
    @NonNull Executor executor,
    @NonNull Consumer<@NonNull List<@NonNull SplitInfo>> consumer
)

Registers a listener for updates about the active split state(s) that this activity is part of.

final void

Unregisters a listener that was previously registered via addSplitListener.

Public constructors

SplitControllerCallbackAdapter

Added in 1.1.0
public SplitControllerCallbackAdapter(@NonNull SplitController controller)

Public methods

addSplitListener

Added in 1.1.0
public final void addSplitListener(
    @NonNull Activity activity,
    @NonNull Executor executor,
    @NonNull Consumer<@NonNull List<@NonNull SplitInfo>> consumer
)

Registers a listener for updates about the active split state(s) that this activity is part of. An activity can be in zero, one or more active splits. More than one active split is possible if an activity created multiple containers to side, stacked on top of each other. Or it can be in two different splits at the same time - in a secondary container for one (it was launched to the side) and in the primary for another (it launched another activity to the side). The reported splits in the list are ordered from bottom to top by their z-order, more recent splits appearing later. Guaranteed to be called at least once to report the most recent state.

Parameters
@NonNull Activity activity

only split that this Activity is part of will be reported.

@NonNull Executor executor

when there is an update to the active split state(s), the consumer will be invoked on this Executor.

@NonNull Consumer<@NonNull List<@NonNull SplitInfo>> consumer

Consumer that will be invoked on the executor when there is an update to the active split state(s).

removeSplitListener

Added in 1.1.0
public final void removeSplitListener(
    @NonNull Consumer<@NonNull List<@NonNull SplitInfo>> consumer
)

Unregisters a listener that was previously registered via addSplitListener.

Parameters
@NonNull Consumer<@NonNull List<@NonNull SplitInfo>> consumer

the previously registered Consumer to unregister.