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. Apps using a Session consider its lifecycle to ensure that native resources are released when the session is no longer needed. If your activity is a single XR-enabled activity, it is recommended to call the Session object's lifecycle methods from the activity's lifecycle methods using a lifecycle-aware component. See create, resume, pause, and destroy for more details.

Summary

Public companion functions

SessionCreateResult
create(activity: Activity, coroutineDispatcher: CoroutineDispatcher)

Creates a new Session.

Public functions

SessionConfigureResult

Sets or changes the configuration to use.

Unit

Destroys the session, releasing any resources acquired by the session.

Unit

Pauses execution of the session.

SessionResumeResult

Starts or resumes the session.

Public properties

StateFlow<CoreState>

A StateFlow of the current state.

Public companion functions

create

Added in 1.0.0-alpha01
fun create(
    activity: Activity,
    coroutineDispatcher: CoroutineDispatcher = CoroutineDispatchers.Lightweight
): SessionCreateResult

Creates a new Session.

Creating a session requires the android.permission.SCENE_UNDERSTANDING permission to be granted.

Parameters
activity: Activity

the Activity that owns the session.

coroutineDispatcher: CoroutineDispatcher = CoroutineDispatchers.Lightweight

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

Returns
SessionCreateResult

the result of the operation. Can be SessionCreateSuccess, which contains the newly created session, or SessionCreatePermissionsNotGranted if the required permissions haven't been granted.

Public functions

configure

Added in 1.0.0-alpha01
fun configure(): SessionConfigureResult

Sets or changes the configuration to use.

Returns
SessionConfigureResult

the result of the operation. This will be a SessionConfigureSuccess if the configuration was successful, or a SessionConfigureConfigurationNotSupported if the SessionConfiguration is not supported.

Throws
kotlin.IllegalStateException

if the session has been destroyed.

destroy

Added in 1.0.0-alpha01
fun destroy(): Unit

Destroys the session, releasing any resources acquired by the session. Objects tracked by the system will not receive updates.

Calling this method on a destroyed session is a no-op. Additionally, calling this method on an active session will first call pause.

pause

Added in 1.0.0-alpha01
fun pause(): Unit

Pauses execution of the session. Objects tracked by the session will not receive updates. The system state will be retained in memory.

Calling this method on an inactive session is a no-op.

Throws
kotlin.IllegalStateException

if the session has been destroyed.

resume

Added in 1.0.0-alpha01
fun resume(): SessionResumeResult

Starts or resumes the session.

Resuming a session requires the android.permission.SCENE_UNDERSTANDING to be granted.

Returns
SessionResumeResult

the result of the operation. Can be SessionResumeSuccess if the session was successfully resumed, or SessionResumePermissionsNotGranted if the required permissions haven't been granted.

Throws
kotlin.IllegalStateException

if the session has been destroyed.

Public properties

state

Added in 1.0.0-alpha01
val stateStateFlow<CoreState>

A StateFlow of the current state.