class Session


A session is the main entrypoint to features provided by ARCore for Jetpack XR. It manages the system's state and its lifecycle, and contains the state of objects tracked by ARCore for Jetpack XR.

This class owns a significant amount of native heap memory. The Session's lifecycle will be scoped to the Activity that owns it.

Summary

Public companion functions

SessionCreateResult
create(
    context: Context,
    coroutineContext: CoroutineContext,
    lifecycleOwner: LifecycleOwner
)

Creates a new Session.

Public functions

SessionConfigureResult
configure(config: Config)

Sets or changes the Config to use for the Session.

Public properties

Config
@GuardedBy(value = "lock")
config

The current state of the runtime configuration.

Context

the Context the Session belongs to

CoroutineScope

the CoroutineScope for coroutines within the Session

LifecycleOwner

the owner of the Android Lifecycle the Session belongs to

StateFlow<CoreState>

A StateFlow of the current state.

Extension properties

Scene

Gets the Scene associated with this Session.

Public companion functions

create

Added in 1.0.0-alpha15
fun create(
    context: Context,
    coroutineContext: CoroutineContext = EmptyCoroutineContext,
    lifecycleOwner: LifecycleOwner = context as LifecycleOwner
): SessionCreateResult

Creates a new Session.

The thread on which this method should be called depends on the features being used:

  • If you are using SceneCore rendering APIs, this method must be called on the Main Thread.

Thread Safety Warning: This method performs significant disk I/O, including loading native libraries. If StrictMode is enabled, calling this on the Main Thread (UI Thread) will trigger a android.os.StrictMode DiskReadViolation.

Example for calling on a WorkerThread for Projected devices:

lifecycleScope.launch {
val result = withContext(Dispatchers.IO) {
Session.create(context)
}
}
Parameters
context: Context

the context provided for the session's resources.

coroutineContext: CoroutineContext = EmptyCoroutineContext

the CoroutineContext that will be used to handle the session's coroutines.

lifecycleOwner: LifecycleOwner = context as LifecycleOwner

the lifecycleOwner whose lifecycle controls the runtime state of the session. Defaults to using the context as the owner if not provided.

Returns
SessionCreateResult

the result of the operation. Can be SessionCreateSuccess, which contains the newly created session, or another SessionCreateResult if a certain criteria was not met.

Throws
SecurityException

if the Session is backed by Google Play Services for AR and android.Manifest.permission.CAMERA has not been granted to the calling application.

Public functions

configure

Added in 1.0.0-alpha15
fun configure(config: Config): SessionConfigureResult

Sets or changes the Config to use for the Session.

The passed config will overwrite all mode values. Not all runtimes will support every mode, and the desired modes should first be queried for availability using androidx.xr.runtime.XrDevice before configuring. Example: androidx.xr.runtime.XrDevice.isGeospatialModeSupported.

It is recommended to use and modify an instance of Config.Builder to maintain the current desired configuration state. A instance of Config to pass to this function can be created using Config.Builder.build.

Note that enabling most configurations will increase hardware resource consumption and should only be enabled if needed.

Parameters
config: Config

the Config that will be enabled if successful.

Returns
SessionConfigureResult

the result of the operation. This will be a SessionConfigureSuccess if the configuration was successful, or another SessionConfigureResult if a certain configuration criteria was not met. In the case of the latter, the previous Session.config will remain active.

Throws
IllegalStateException

if the session has been destroyed.

UnsupportedOperationException

if the configuration is not supported.

SecurityException

if the necessary permissions have not been granted to the calling application for the provided configuration.

Public properties

config

Added in 1.0.0-alpha15
@GuardedBy(value = "lock")
val configConfig

The current state of the runtime configuration.

context

Added in 1.0.0-alpha15
val contextContext

the Context the Session belongs to

coroutineScope

Added in 1.0.0-alpha15
val coroutineScopeCoroutineScope

the CoroutineScope for coroutines within the Session

lifecycleOwner

Added in 1.0.0-alpha15
val lifecycleOwnerLifecycleOwner

the owner of the Android Lifecycle the Session belongs to

state

Added in 1.0.0-alpha15
val stateStateFlow<CoreState>

A StateFlow of the current state.

Extension properties

Session.scene

val Session.sceneScene

Gets the Scene associated with this Session.

Accessing the scene in a destroyed activity can be dangerous.

The Scene is the primary interface for creating and managing spatial content. There is a single Scene instance for each Session.

See also
Scene