ActivityEmbeddingControllerCallbackAdapter


public final class ActivityEmbeddingControllerCallbackAdapter


An adapted interface for ActivityEmbeddingController that provides callback shaped APIs to report the latest EmbeddedActivityWindowInfo.

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

Summary

Public constructors

creates a callback adapter of ActivityEmbeddingController.embeddedActivityWindowInfo flow API.

Public methods

final void

Registers a listener for updates of EmbeddedActivityWindowInfo of activity.

final void

Unregisters a listener that was previously registered via addEmbeddedActivityWindowInfoListener.

Public constructors

ActivityEmbeddingControllerCallbackAdapter

Added in 1.4.0-alpha05
public ActivityEmbeddingControllerCallbackAdapter(
    @NonNull ActivityEmbeddingController controller
)

creates a callback adapter of ActivityEmbeddingController.embeddedActivityWindowInfo flow API.

Public methods

addEmbeddedActivityWindowInfoListener

Added in 1.4.0-alpha05
@RequiresWindowSdkExtension(version = 6)
public final void addEmbeddedActivityWindowInfoListener(
    @NonNull Activity activity,
    @NonNull Executor executor,
    @NonNull Consumer<@NonNull EmbeddedActivityWindowInfo> listener
)

Registers a listener for updates of EmbeddedActivityWindowInfo of activity.

The listener will immediately be invoked with the latest value upon registration if the activity is currently embedded as EmbeddedActivityWindowInfo.isEmbedded is true.

When the activity is embedded, the listener will be invoked when EmbeddedActivityWindowInfo is changed. When the activity is not embedded, the listener will not be triggered unless the activity is becoming non-embedded from embedded.

Note that this API is only supported on the device with WindowSdkExtensions.extensionVersion equal to or larger than 6. If WindowSdkExtensions.extensionVersion is less than 6, this listener will not be invoked.

Parameters
@NonNull Activity activity

the Activity that is interested in getting the embedded window info.

@NonNull Executor executor

the Executor to dispatch the EmbeddedActivityWindowInfo change.

@NonNull Consumer<@NonNull EmbeddedActivityWindowInfo> listener

the Consumer that will be invoked on the executor when there is an update to EmbeddedActivityWindowInfo.

removeEmbeddedActivityWindowInfoListener

Added in 1.4.0-alpha05
@RequiresWindowSdkExtension(version = 6)
public final void removeEmbeddedActivityWindowInfoListener(
    @NonNull Consumer<@NonNull EmbeddedActivityWindowInfo> listener
)

Unregisters a listener that was previously registered via addEmbeddedActivityWindowInfoListener.

It's no-op if the listener has not been registered.

Parameters
@NonNull Consumer<@NonNull EmbeddedActivityWindowInfo> listener

the previously registered Consumer to unregister.