API reference
API reference
Select your platform
No SDKs available
No versions available

AppSystemActivity Class

Extends VrActivity
Implements AppSystemCommon
Modifiers: open
AppSystemActivity serves as the base class for all Spatial activities. It contains all Android activity lifecycle callbacks: onCreate, onStop, onDestroy and others. It also provides scene lifecycle callbacks: onSceneReady and onSceneTick. This class also provides hooks to override system features through registerSystemFeatures and to register panels through registerPanels.

Signature

open class AppSystemActivity : VrActivity, AppSystemCommon

Constructors

AppSystemActivity ()
Signature
constructor()

Properties

componentManager : ComponentManager
[Get]
Signature
val componentManager: ComponentManager
glXFManager : GLXFManager
[Get]
Signature
val glXFManager: GLXFManager
panelRegistrations : HashMap<Int, PanelRegistration>
[Get]
Signature
val panelRegistrations: HashMap<Int, PanelRegistration>
panelViewLifecycleOwner : PanelViewLifecycleOwner
[Get]
Signature
val AppSystemActivity.panelViewLifecycleOwner: PanelViewLifecycleOwner
registeredReceivers : List
[Get][Set]
Signature
var registeredReceivers: List
scene : Scene
[Get]
Signature
val scene: Scene
spatialContext : SpatialContext
[Get]
Signature
val spatialContext: SpatialContext
systemManager : SystemManager
[Get]
Signature
val systemManager: SystemManager

Functions

attachLifecycleToRootView ( rootView , panelViewLifecycleOwner )
Signature
fun AppSystemActivity.attachLifecycleToRootView(rootView: View?, panelViewLifecycleOwner: PanelViewLifecycleOwner? = null)
Parameters
rootView: View?
panelViewLifecycleOwner: PanelViewLifecycleOwner?
audioPauseMode ()
Controls when audio is automatically paused and resumed.
Override this method to change the audio pause behavior:
Example:
override fun audioPauseMode(): AudioPauseMode = AudioPauseMode.OPENXR_FOCUS

Signature
open fun audioPauseMode(): AudioPauseMode
dispatchGenericMotionEvent ( event )
Dispatches a generic motion event to the appropriate game controller.
Signature
open fun dispatchGenericMotionEvent(event: MotionEvent): Boolean
Parameters
event: MotionEvent
  The motion event to dispatch.
Returns
Boolean
  True if the event was handled, false otherwise.
dispatchKeyEvent ( event )
Dispatches a key event to the appropriate game controller.
Signature
open fun dispatchKeyEvent(event: KeyEvent): Boolean
Parameters
event: KeyEvent
  The key event to dispatch.
Returns
Boolean
  True if the event was handled, false otherwise.
doFrame ( frameTimeNanos )
Called when a new display frame is being rendered.
Signature
open fun doFrame(frameTimeNanos: Long)
Parameters
frameTimeNanos: Long
findFeature ()
Signature
inline fun <T : SpatialFeature> findFeature(): T
Returns
findFeature ( clazz )
Signature
fun <T : SpatialFeature> findFeature(clazz: KClass<T>): T
Parameters
clazz: KClass
Returns
getComponentManager ()
Returns the singleton component manager for the application.
Signature
fun getComponentManager(): ComponentManager
Returns
  The component manager for the application.
getDataModel ()
Returns the singleton DataModel for the application.
Signature
fun getDataModel(): DataModel
Returns
  The data model for the application.
getGameControllerDeviceIds ()
Returns a set of device IDs for all connected game controllers.
Signature
fun getGameControllerDeviceIds(): Set<Int>
Returns
Set
  A set of device IDs for all connected game controllers.
getSceneObject ()
Returns the singleton scene object for the application.
Signature
fun getSceneObject(): Scene
Returns
  The scene object for the application.
getSystemManager ()
Returns the singleton system manager for the application.
Signature
fun getSystemManager(): SystemManager
Returns
  The system manager for the application.
internalOnSessionStateChanged ( stateValue )
Internal JNI callback that receives the session state as an integer from C++. This method converts the integer to a SessionState enum and calls the public callback. Applications should not override this method.
Signature
open fun internalOnSessionStateChanged(stateValue: Int)
Parameters
stateValue: Int
  The session state as an integer (0-8)
loadLibrary ( name )
Loads a native C++ library. This method should be called in onCreate().
Signature
open fun loadLibrary(name: String)
Parameters
name: String
  The name of the library without the filename extensions.
onCreate ( savedInstanceState )
Called when the activity is first created. Override this lifecycle callback method to do all of your normal static set up: creating views, setting the content view, register Components as well as Systems and etc. You can also perform dynamic setup, such as querying for data and loading it into the view. This will also be called for all activities that are restored to their state when last paused or stopped. If you override this method, be sure to call super.onCreate().
Signature
open override fun onCreate(savedInstanceState: Bundle?)
Parameters
savedInstanceState: Bundle?
  If the activity is being re-initialized after previously being shut down then this Bundle contains the data it most recently supplied in onSaveInstanceState(Bundle). Note: Otherwise it is null.
onDestroy ()
Called when the activity is destroyed. Override this method to perform any final cleanup. If you override this method, be sure to call super.onDestroy()
Note: This is not guaranteed to be called, as the OS may kill the activity's hosting process at any time.
Signature
open override fun onDestroy()
onHMDMounted ()
Signature
open fun onHMDMounted()
onHMDUnmounted ()
Signature
open fun onHMDUnmounted()
onPause ()
Called as part of the activity lifecycle when an activity is going into the background, but has not yet been killed. The counterpart to onResume(). If you override this method, be sure to call super.onPause().
Signature
open fun onPause()
onPostResume ()
Called after activity resume is complete. If you override this method, be sure to call super.onPostResume().
Signature
open fun onPostResume()
onRecenter ( isUserInitiated )
This hook is called when the VRActivity is recentered.
Signature
open fun onRecenter(isUserInitiated: Boolean)
Parameters
isUserInitiated: Boolean
onResume ()
Called when the activity will start interacting with the user. If you override this method, be sure to call super.onResume()
Signature
open fun onResume()
onSceneReady ()
This hook is called on the first onResume(), after the scene is loaded in onCreate(). This is where you should call the scene APIs such as setReferenceSpace to define your scene. If you override this method, be sure to call super.onSceneReady().
Signature
open override fun onSceneReady()
onSceneTick ()
Called every tick in the application. It is advisable to use this lifecycle callback method sparingly and to create Systems that manage logic in every tick. If you override this method, be sure to call super.onSceneTick().
Signature
open override fun onSceneTick()
onSessionStateChanged ( state )
Called when the OpenXR session state changes.
This callback is invoked whenever the XR runtime transitions between different session states. Applications can override this method to respond to state changes, such as preparing resources when the session becomes ready, or pausing rendering when losing focus.
Signature
open fun onSessionStateChanged(state: SessionState)
Parameters
state: SessionState
  The new session state
onSpatialShutdown ()
Called when the AppActivity is shutting down. Write all clean up logic of the Spatial App in this callback. If you override this method, be sure to call super.onSpatialShutdown().
Signature
open override fun onSpatialShutdown()
onStart ()
Called when the activity is becoming visible to the user. If you override this method, be sure to call super.onStart().
Signature
open fun onStart()
onStop ()
Called when the app is no longer visible to the user. You will next receive either onRestart(), onDestroy(), or nothing, depending on later user activity. If you override this method, be sure to call super.onStop().
Signature
open fun onStop()
onVRPause ()
This hook is called when the VRActivity switches from immersive to non-immersive mode. It will invoke all the onVRPause() hooks of the registered SpatialFeatures.
Signature
open fun onVRPause()
onVRReady ()
This hook is called when the immersive Spatial application is first loaded or is changed from 2D mode to immersive (VR) mode. It will invoke all the onVRReady() hooks of the registered SpatialFeatures.
Signature
open fun onVRReady()
pinGameController ( deviceId , func )
Pins a game controller with the given device ID and associates it with the given function.
Parameters
deviceId: Int
  The device ID of the game controller to pin.
func: Function2
  The function to associate with the game controller.
registerFeatures ()
Override this method to register your own SpatialFeatures. This is called in onCreate().
Signature
open fun registerFeatures(): List<SpatialFeature>
Returns
List
registerMeshCreator ( baseUrl , creator )
Registers a mesh creator for a base URL pattern.
The creator will be invoked for any mesh URI that matches the base URL (scheme + authority + path). Query parameters from the full URI will be passed to the creator for customization.
Example:
// Register a creator for "mesh://custom/sphere"
registerMeshCreator("mesh://custom/sphere") { entity, uri ->
    val radius = uri.getQueryParameter("radius")?.toFloatOrNull() ?: 1.0f
    val color = uri.getQueryParameter("color") ?: "white"
    createSphere(entity, radius, color)
}
// Later, use with parameters:
Mesh(Uri.parse("mesh://custom/sphere?radius=2.5&color=red"))

Parameters
baseUrl: String
  The base URL to match (e.g., "mesh://myapp/custom"). Query parameters are ignored in matching.
creator: Function2
  Function that takes an Entity and the full URI (including query params), returns a SceneMesh
registerMeshCreator ( meshURL , creator )
Registers a simple mesh creator that doesn't need URI parameters.
This is a convenience method for mesh creators that don't need to read query parameters from the URI. The mesh URL must match exactly.
Example:
registerMeshCreator("mesh://custom") { entity ->
    SceneMesh.box(-0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f, material)
}

Signature
open fun registerMeshCreator(meshURL: String, creator: (entity: Entity) -> SceneMesh)
Parameters
meshURL: String
  The exact mesh URL to match
creator: Function1
  Function that takes an Entity and returns a SceneMesh
registerPanel ( panelRegistration )
This is used to register a panel. This is called within the onCreate lifecycle for every PanelRegistration returned by registerPanels. It is strongly discouraged to call this directly to dynamically register panels, as panels should be registered during OnCreate()
Signature
fun registerPanel(panelRegistration: PanelRegistration)
Parameters
panelRegistration: PanelRegistration
registerPanels ()
This hook is where you should register your panels. This is called within the onCreate lifecycle.
Signature
open fun registerPanels(): List<PanelRegistration>
Returns
List
registerRequiredOpenXRExtensions ()
Signature
open fun registerRequiredOpenXRExtensions(): List<String>
Returns
List
registerSystemFeatures ()
This hook is where the application registers SystemFeatures such as ToolkitFeature. This is called within the onCreate lifecycle. Note that to register a custom SpatialFeature, override registerFeatures instead.
Signature
open override fun registerSystemFeatures(): List<SpatialFeature>
Returns
List
renderConfiguration ()
Controls the render resolution scaling for VR applications.
This configuration allows adjusting the resolution at which VR content is rendered, which affects both visual quality and performance.
Signature
open fun renderConfiguration(): RenderConfiguration
runOnMainThread ( runnable )
This method provides a way to run a Runnable on the activity's main thread.
Signature
fun runOnMainThread(runnable: Runnable)
Parameters
runnable: Runnable
setBaseHref ( baseHref )
Sets the base href for the application.
Signature
open fun setBaseHref(baseHref: String)
Parameters
baseHref: String
  The new base href for the application.
tryFindFeature ()
Signature
inline fun <T : SpatialFeature> tryFindFeature(): T?
tryFindFeature ( clazz )
Signature
fun <T : SpatialFeature> tryFindFeature(clazz: KClass<T>): T?
Parameters
clazz: KClass
unpinGameController ( deviceId )
Unpins a game controller with the given device ID.
Signature
fun unpinGameController(deviceId: Int)
Parameters
deviceId: Int
  The device ID of the game controller to unpin.
unregisterMeshCreator ( baseUrl )
Unregisters a mesh creator for the given base URL.
Signature
open fun unregisterMeshCreator(baseUrl: String)
Parameters
baseUrl: String
  The base URL that was registered
useVolumes ()
Signature
open fun useVolumes(): Boolean
Returns
Boolean
Did you find this page helpful?