# SpatialWindow

Artifact: [androidx.xr.scenecore:scenecore](https://developer.android.com/jetpack/androidx/releases/xr-scenecore) [View Source](https://cs.android.com/search?q=file:androidx/xr/scenecore/SpatialWindow.kt+class:androidx.xr.scenecore.SpatialWindow) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

*** ** * ** ***


```
public static class SpatialWindow
```

<br />

*** ** * ** ***

Methods used to manage the `https://developer.android.com/reference/android/app/Activity.html`'s main spatial window when it is displayed in Home Space Mode.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/xr/runtime/Session` |   |

## Summary

| ### Constants |
|---|---|
| `static final float` | `https://developer.android.com/reference/androidx/xr/scenecore/SpatialWindow#NO_PREFERRED_ASPECT_RATIO()` Constant to indicate that there are no preferences for the aspect ratio. |

| ### Public fields |
|---|---|
| `static @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/SpatialWindow` | `https://developer.android.com/reference/androidx/xr/scenecore/SpatialWindow#INSTANCE()` |

| ### Public methods |
|---|---|
| `final void` | `https://developer.android.com/reference/androidx/xr/scenecore/SpatialWindow#setPreferredAspectRatio(androidx.xr.runtime.Session,android.app.Activity,kotlin.Float)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/Session session, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/app/Activity.html activity, float preferredRatio )` Sets a preferred main panel aspect ratio for Home Space. |

## Constants

### NO_PREFERRED_ASPECT_RATIO

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
public static final float NO_PREFERRED_ASPECT_RATIO
```

Constant to indicate that there are no preferences for the aspect ratio.

## Public fields

### INSTANCE

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
public static @NonNull SpatialWindow INSTANCE
```

## Public methods

### setPreferredAspectRatio

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
public final void setPreferredAspectRatio(
    @NonNull Session session,
    @NonNull Activity activity,
    float preferredRatio
)
```

Sets a preferred main panel aspect ratio for Home Space.

The ratio is only applied to the `https://developer.android.com/reference/android/app/Activity.html`. If the activity launches another activity in the same task, the ratio is not applied to the new activity. Also, while the activity is in Full Space, the preference is ignored.

If the activity's current aspect ratio differs from the `preferredRatio`, the panel is automatically resized. This resizing preserves the panel's area. To avoid runtime resizing, consider specifying the desired aspect ratio in your [application's manifest file](https://developer.android.com/guide/topics/manifest/manifest-intro). This ensures your activity launches with the preferred aspect ratio from the start.

The default preference is set to `https://developer.android.com/reference/androidx/xr/scenecore/SpatialWindow#NO_PREFERRED_ASPECT_RATIO()` allowing the user to resize the spatial window to any aspect ratio. The actual initial aspect ratio is determined by system-defined behavior.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/Session session` | the session from which to set the preference. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/app/Activity.html activity` | the activity for which to set the preference. |
| `float preferredRatio` | the aspect ratio determined by taking the panel's width over its height. Use `https://developer.android.com/reference/androidx/xr/scenecore/SpatialWindow#NO_PREFERRED_ASPECT_RATIO()` to indicate that there are no preferences. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if preferredRatio is smaller than 1:12 or greater than 12:1. A value \<= 0.0f indicates no preference and will not throw exception. |