public final class Session implements 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 methods

static final @NonNull SessionCreateResult
create(
    @NonNull Activity activity,
    @NonNull CoroutineContext coroutineContext
)

Creates a new Session.

final void

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

@NonNull Lifecycle
final @NonNull StateFlow<@NonNull CoreState>

A StateFlow of the current state.

final void

Pauses execution of the session.

final @NonNull SessionResumeResult

Starts or resumes the session.

Extension functions

final @NonNull Scene

Public methods

create

Added in 1.0.0-alpha04
public static final @NonNull SessionCreateResult create(
    @NonNull Activity activity,
    @NonNull CoroutineContext coroutineContext
)

Creates a new Session.

Parameters
@NonNull Activity activity

the Activity that owns the session.

@NonNull CoroutineContext coroutineContext

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

Returns
@NonNull 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.

destroy

Added in 1.0.0-alpha04
public final void destroy()

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.

getLifecycle

Added in 1.0.0-alpha04
public @NonNull Lifecycle getLifecycle()

getState

Added in 1.0.0-alpha04
public final @NonNull StateFlow<@NonNull CoreStategetState()

A StateFlow of the current state.

pause

Added in 1.0.0-alpha04
public final void pause()

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
public final @NonNull SessionResumeResult resume()

Starts or resumes the session.

Returns
@NonNull 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.

Extension functions

SessionExtKt.getScene

public final @NonNull Scene SessionExtKt.getScene(@NonNull Session receiver)