class Session : LifecycleOwner


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, coroutineContext: CoroutineContext)

Creates a new Session.

Public functions

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

open Lifecycle
StateFlow<CoreState>

A StateFlow of the current state.

Extension properties

Scene

Public companion functions

create

Added in 1.0.0-alpha04
fun create(
    activity: Activity,
    coroutineContext: CoroutineContext = CoroutineContexts.Lightweight
): SessionCreateResult

Creates a new Session.

Parameters
activity: Activity

the Activity that owns the session.

coroutineContext: CoroutineContext = CoroutineContexts.Lightweight

the CoroutineContext 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

destroy

Added in 1.0.0-alpha04
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-alpha04
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-alpha04
fun resume(): SessionResumeResult

Starts or resumes the session.

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

lifecycle

Added in 1.0.0-alpha04
open val lifecycleLifecycle

state

Added in 1.0.0-alpha04
val stateStateFlow<CoreState>

A StateFlow of the current state.

Extension properties