Session
public final 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 methods |
|
|---|---|
final @NonNull SessionConfigureResult |
Sets or changes the |
static final @NonNull SessionCreateResult |
create(Creates a new |
final @NonNull Config |
The current state of the runtime configuration. |
final @NonNull Context |
the |
final @NonNull CoroutineScope |
the |
final @NonNull LifecycleOwner |
the owner of the Android |
final @NonNull StateFlow<@NonNull CoreState> |
getState()A |
Extension functions |
|
|---|---|
final @NonNull Scene |
SessionExt.getScene(@NonNull Session receiver)Gets the |
Public methods
configure
public final @NonNull SessionConfigureResult configure(@NonNull Config config)
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 modify the current Config to avoid unnecessarily resetting the system. This can be done using Config.Builder as follows:
val newConfig = Config.Builder(session.config)
.setFeature(Feature.ENABLED)
.build()
session.configure(newConfig)
Note that enabling most configurations will increase hardware resource consumption and should only be enabled if needed.
| Returns | |
|---|---|
@NonNull SessionConfigureResult |
the result of the operation. This will be a |
| 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. |
create
public static final @NonNull SessionCreateResult create(
@NonNull Context context,
@NonNull CoroutineContext coroutineContext,
@NonNull LifecycleOwner lifecycleOwner
)
Creates a new Session.
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.StrictModeDiskReadViolation.
Example for calling on a worker thread:
lifecycleScope.launch {
val result = withContext(Dispatchers.IO) {
Session.create(context)
}
}| Parameters | |
|---|---|
@NonNull Context context |
the |
@NonNull CoroutineContext coroutineContext |
the |
@NonNull LifecycleOwner lifecycleOwner |
the |
| Returns | |
|---|---|
@NonNull SessionCreateResult |
the result of the operation. Can be |
| Throws | |
|---|---|
SecurityException |
if the |
getConfig
public final @NonNull Config getConfig()
The current state of the runtime configuration.
getContext
public final @NonNull Context getContext()
the Context the Session belongs to
getCoroutineScope
public final @NonNull CoroutineScope getCoroutineScope()
the CoroutineScope for coroutines within the Session
getLifecycleOwner
public final @NonNull LifecycleOwner getLifecycleOwner()
the owner of the Android Lifecycle the Session belongs to
Extension functions
SessionExt.getScene
public final @NonNull Scene SessionExt.getScene(@NonNull Session receiver)
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 |