Session
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 |
|
|---|---|
suspend SessionCreateResult |
create(Creates a new |
Public functions |
|
|---|---|
SessionConfigureResult |
Sets or changes the |
Public properties |
|
|---|---|
Config |
The current state of the runtime configuration. |
Context |
the |
CoroutineScope |
the |
LifecycleOwner |
the owner of the Android |
StateFlow<CoreState> |
A |
Public companion functions
create
suspend fun create(
context: Context,
coroutineContext: CoroutineContext = EmptyCoroutineContext,
lifecycleOwner: LifecycleOwner = context as LifecycleOwner
): SessionCreateResult
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 | |
|---|---|
context: Context |
the |
coroutineContext: CoroutineContext = EmptyCoroutineContext |
the |
lifecycleOwner: LifecycleOwner = context as LifecycleOwner |
the |
| Returns | |
|---|---|
SessionCreateResult |
the result of the operation. Can be |
| Throws | |
|---|---|
SecurityException |
if the |
Public functions
configure
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 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 | |
|---|---|
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. |
Public properties
config
@GuardedBy(value = "configurationMutex")
val config: Config
The current state of the runtime configuration.
coroutineScope
val coroutineScope: CoroutineScope
the CoroutineScope for coroutines within the Session
lifecycleOwner
val lifecycleOwner: LifecycleOwner
the owner of the Android Lifecycle the Session belongs to