ActivityEmbeddingOptions

Added in 1.4.0-alpha05

public final class ActivityEmbeddingOptions


Summary

Public methods

static final @NonNull Bundle
@RequiresWindowSdkExtension(version = 5)
setLaunchingActivityStack(
    @NonNull Bundle receiver,
    @NonNull Context context,
    @NonNull ActivityStack activityStack
)

Sets the target launching ActivityStack to the given Bundle.

Public methods

setLaunchingActivityStack

@RequiresWindowSdkExtension(version = 5)
public static final @NonNull Bundle setLaunchingActivityStack(
    @NonNull Bundle receiver,
    @NonNull Context context,
    @NonNull ActivityStack activityStack
)

Sets the target launching ActivityStack to the given Bundle.

The Bundle then could be used to launch an Activity to the top of the ActivityStack through Activity.startActivity. If there's a bundle used for customizing how the Activity should be started by ActivityOptions.toBundle or androidx.core.app.ActivityOptionsCompat.toBundle, it's suggested to use the bundle to call this method.

It is suggested to use a visible ActivityStack reported by SplitController.splitInfoList or OverlayController.overlayInfo, or the launching activity will be launched on the default target if the activityStack no longer exists in the host task. The default target could be the top of the visible split's secondary ActivityStack, or the top of the host task.

Below samples are use cases to specify the launching ActivityStack.

import androidx.core.app.ActivityOptionsCompat
import androidx.window.embedding.ActivityStack
import androidx.window.embedding.SplitController
import androidx.window.embedding.setLaunchingActivityStack

var primaryActivityStack: ActivityStack? = null

SplitController.getInstance(primaryActivity).splitInfoList(primaryActivity).collect {
    splitInfoList ->
    primaryActivityStack = splitInfoList.last().primaryActivityStack
}

primaryActivity.startActivity(
    INTENT,
    ActivityOptionsCompat.makeBasic()
        .toBundle()!!
        .setLaunchingActivityStack(primaryActivity, primaryActivityStack!!)
)
import androidx.core.app.ActivityOptionsCompat
import androidx.window.embedding.ActivityStack
import androidx.window.embedding.OverlayController
import androidx.window.embedding.setLaunchingActivityStack

var overlayActivityStack: ActivityStack? = null

OverlayController.getInstance(context).overlayInfo(TAG_OVERLAY).collect { overlayInfo ->
    overlayActivityStack = overlayInfo.activityStack
}

// The use case is to launch an Activity to an existing overlay ActivityStack from the overlain
// Activity. If activityStack is not specified, the activity is launched to the top of the
// host task behind the overlay ActivityStack.
overlainActivity.startActivity(
    INTENT,
    ActivityOptionsCompat.makeBasic()
        .toBundle()!!
        .setLaunchingActivityStack(overlainActivity, overlayActivityStack!!)
)
Parameters
@NonNull Context context

The android.content.Context that is going to be used for launching activity with this Bundle, which is usually be the android.app.Activity of the app that hosts the task.

@NonNull ActivityStack activityStack

The target ActivityStack for launching.