קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
Session מספק את הממשק הראשי לפונקציונליות המרחבית של האפליקציה. כל פעילות במרחב צריכה ליצור מכונה של Session ולשמור אותה. לאחר היצירה, האפליקציה יכולה להשתמש בממשקי Session כדי ליצור ישויות של תוכן במרחב, כמו פאנלים או מודלים תלת-ממדיים, וגם להגדיר סביבה מרחבית, לזהות את מיקום המשתמש ולעגן תוכן בעולם האמיתי.
גישה לסשן מ-Jetpack Compose for XR
כשמשתמשים ב-Jetpack Compose ל-XR, הסשן נוצר בשבילכם וניתן לגשת אליו באמצעות LocalSession.current. דוגמה:
אם אתם יוצרים ישויות מרחביות מספריית SceneCore, תצטרכו ליצור את הסשן.
אפשר ליצור סשן רק במכשיר Android XR. ניסיון ליצור סשן במכשיר לא תואם יביא לתוצאה של כשל. כדי ליצור סשן, מעבירים פעילות ל-method create(), כפי שמתואר בדוגמה הבאה.
when(valresult=Session.create(this)){isSessionCreateSuccess->{valxrSession=result.session// ...}else->
TODO(/* A different unhandled exception was thrown. */)}
דוגמאות התוכן והקוד שבדף הזה כפופות לרישיונות המפורטים בקטע רישיון לתוכן. Java ו-OpenJDK הם סימנים מסחריים או סימנים מסחריים רשומים של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-08-23 (שעון UTC).
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 2025-08-23 (שעון UTC)."],[],[],null,["# Session\n\nThe [`Session`](/reference/kotlin/androidx/xr/runtime/Session) provides the primary interface to spatialized functionality\nfor the application. Each spatialized Activity must create and hold an instance\nof `Session`. Once created, the application can use the `Session` interfaces to\ncreate spatialized content entities such as panels or 3d models, as well as [set\na spatial environment](/develop/xr/jetpack-xr-sdk/add-environments), [identify user position](/reference/kotlin/androidx/xr/scenecore/SpatialUser), and [anchor content](/develop/xr/jetpack-xr-sdk/work-with-entities)\nto the real world.\n| **Caution:** Due to a [known issue](/jetpack/androidx/releases/xr-scenecore#1.0.0-alpha04) that ties the session to the Activity lifecycle, the session can become invalid in various situations that automatically recreate the activity. These include, but are not limited to resizing a main panel, connecting peripherals, and changing between light and dark theme. If you run into session invalidation issues, you may need to make your main panel non-resizable, use a dynamic panel entity, disable activity recreation for [specific config changes](/guide/topics/resources/runtime-changes#restrict-activity), or disable light or dark theme changes.\n\nAccess Session from Jetpack Compose for XR\n------------------------------------------\n\nWhen using Jetpack Compose for XR, the session is created for you and can be\naccessed using [`LocalSession.current`](/reference/kotlin/androidx/xr/compose/platform/package-summary#LocalSession()). See the following example:\n\n\n```kotlin\n@Composable\nfun ComposableUsingSession() {\n val session = LocalSession.current\n}https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/xr/src/main/java/com/example/xr/runtime/Session.kt#L26-L29\n```\n\n\u003cbr /\u003e\n\nAccess Session from Jetpack SceneCore\n-------------------------------------\n\nIf you are creating spatialized entities from the SceneCore library, you'll need\nto create the session.\n\nCreating a session is only supported on an Android XR device. Attempting to\ncreate a session on an incompatible device will result in a failed result. To\ncreate a session, pass an activity to the [`create()`](/reference/kotlin/androidx/xr/runtime/Session#create(android.app.Activity,kotlin.coroutines.CoroutineContext)) method, as shown in\nthe following example.\n\n\n```kotlin\nwhen (val result = Session.create(this)) {\n is SessionCreateSuccess -\u003e {\n val xrSession = result.session\n // ...\n }\n else -\u003e\n TODO(/* A different unhandled exception was thrown. */)\n}https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/xr/src/main/java/com/example/xr/runtime/Session.kt#L34-L41\n```\n\n\u003cbr /\u003e\n\n| **Note:** Some features, such as [hand tracking](/develop/xr/jetpack-xr-sdk/arcore/hands) and [plane tracking](/develop/xr/jetpack-xr-sdk/arcore/planes), require additional runtime permissions in order for session configuration to succeed.\n\nWhen a session's activity is destroyed, all spatial UI and 3D content associated\nwith that session is destroyed and the session is no longer valid.\n\nSee also\n--------\n\n- [Check for spatial capabilities](/develop/xr/jetpack-xr-sdk/check-spatial-capabilities)\n- [Transition between HSM and FSM](/develop/xr/jetpack-xr-sdk/transition-home-space-to-full-space)\n- [Add spatial environments to your app](/develop/xr/jetpack-xr-sdk/add-environments)\n- [Add 3D models to your app](/develop/xr/jetpack-xr-sdk/add-3d-models)"]]