ARCore for Jetpack XR allows apps to work with basic concepts of augmented reality (AR), using low-level scene understanding primitives and motion tracking. Use ARCore for Jetpack XR when building AR experiences and you need to use planar data or anchor content to a fixed location in space.
Understand a Session
lifecycle
All objects tracked by ARCore for Jetpack XR must be accessed through a
Session
. Similar to an Activity's lifecycle, Session
objects
also have a lifecycle that must be maintained according to your app's usage of a
Session
object's features. If your app contains a single XR-enabled activity,
consider handling the lifecycle of the Session
using a Lifecycle-aware
component.
Access a Session
A Session
must be created when using ARCore for Jetpack XR.
When using Jetpack Compose for XR, use LocalSession
to access
the session that is created for you.
Resume a session
Resuming a session should be done when your app is ready to handle state changes
from ARCore for Jetpack XR. In many cases, this is done in your Activity's
onResume()
callback, but your app may want to delay
processing until user interaction.
The following code snippet shows an example of resuming a session.
when (val result = session.resume()) { is SessionResumeSuccess -> { // Session has been created successfully. // Attach any successful handlers here. } is SessionResumePermissionsNotGranted -> { // Request permissions in `result.permissions`. } }
See SessionResumeResult
for reasons why a Session
could fail to resume.
Pause a session
When your activity goes to the background, pause the Session
using
[Session.pause()
][Session.pause]. Pausing a session temporarily stops tracking
until the session is resumed, maintaining the state of the perception system.
Destroy a session
To permanently dispose of a Session
, use
[Session.destroy()
][Session.destroy]. This frees resources in use by the
session and destroys all session states.
See also
- Work with Anchors using ARCore for Jetpack XR
- Work with Planes using ARCore for Jetpack XR
- Work with Hands using ARCore for Jetpack XR