# SessionObserver

Artifact: [androidx.privacysandbox.ui:ui-core](https://developer.android.com/jetpack/androidx/releases/privacysandbox-ui) [View Source](https://cs.android.com/search?q=file:androidx/privacysandbox/ui/core/SessionObserver.kt+class:androidx.privacysandbox.ui.core.SessionObserver) Added in [1.0.0-alpha17](https://developer.android.com/jetpack/androidx/releases/privacysandbox-ui#1.0.0-alpha17) Deprecated in [1.0.0-alpha17](https://developer.android.com/jetpack/androidx/releases/privacysandbox-ui#1.0.0-alpha17)

*** ** * ** ***


```
public interface SessionObserver
```

<br />

*** ** * ** ***

> [!CAUTION]
> **This interface is deprecated.**   
> This library is no longer supported.

An interface that can be used by the client of a `https://developer.android.com/reference/androidx/privacysandbox/ui/core/SandboxedUiAdapter.Session` to receive updates about its state. One session may be associated with multiple session observers.

When a new UI session is started, `https://developer.android.com/reference/androidx/privacysandbox/ui/core/SessionObserver#onSessionOpened(androidx.privacysandbox.ui.core.SessionObserverContext)` will be invoked for all registered observers. This callback will contain a `https://developer.android.com/reference/androidx/privacysandbox/ui/core/SessionObserverContext` object containing data which will be constant for the lifetime of the UI session. `https://developer.android.com/reference/androidx/privacysandbox/ui/core/SessionObserver#onUiContainerChanged(android.os.Bundle)` will also be sent when a new session is opened. This callback will contain a `https://developer.android.com/reference/android/os/Bundle.html` representing the UI presentation of the session's view.

During the entire lifetime of the UI session, `https://developer.android.com/reference/androidx/privacysandbox/ui/core/SessionObserver#onUiContainerChanged(android.os.Bundle)` will be sent when the UI presentation has changed. These updates will be throttled.

When the UI session has completed, `https://developer.android.com/reference/androidx/privacysandbox/ui/core/SessionObserver#onSessionClosed()` will be sent. After this point, no more callbacks will be sent and it is safe to free any resources associated with this session observer.

## Summary

| ### Public methods |
|---|---|
| `abstract void` | `[onSessionClosed](https://developer.android.com/reference/androidx/privacysandbox/ui/core/SessionObserver#onSessionClosed())()` **This method is deprecated.** This library is no longer supported. |
| `abstract void` | `[onSessionOpened](https://developer.android.com/reference/androidx/privacysandbox/ui/core/SessionObserver#onSessionOpened(androidx.privacysandbox.ui.core.SessionObserverContext))(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/privacysandbox/ui/core/SessionObserverContext sessionObserverContext)` **This method is deprecated.** This library is no longer supported. |
| `abstract void` | `[onUiContainerChanged](https://developer.android.com/reference/androidx/privacysandbox/ui/core/SessionObserver#onUiContainerChanged(android.os.Bundle))(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/os/Bundle.html uiContainerInfo)` **This method is deprecated.** This library is no longer supported. |

## Public methods

### onSessionClosed

Added in [1.0.0-alpha17](https://developer.android.com/jetpack/androidx/releases/privacysandbox-ui#1.0.0-alpha17) Deprecated in [1.0.0-alpha17](https://developer.android.com/jetpack/androidx/releases/privacysandbox-ui#1.0.0-alpha17)

```
abstract void [onSessionClosed](https://developer.android.com/reference/androidx/privacysandbox/ui/core/SessionObserver#onSessionClosed())()
```

> [!CAUTION]
> **This method is deprecated.**   
> This library is no longer supported.

Called exactly once per session when the `https://developer.android.com/reference/androidx/privacysandbox/ui/core/SandboxedUiAdapter.Session` associated with this session observer closes. No more callbacks will be made on this observer after this point, and any resources associated with it can be freed.

### onSessionOpened

Added in [1.0.0-alpha17](https://developer.android.com/jetpack/androidx/releases/privacysandbox-ui#1.0.0-alpha17) Deprecated in [1.0.0-alpha17](https://developer.android.com/jetpack/androidx/releases/privacysandbox-ui#1.0.0-alpha17)

```
abstract void [onSessionOpened](https://developer.android.com/reference/androidx/privacysandbox/ui/core/SessionObserver#onSessionOpened(androidx.privacysandbox.ui.core.SessionObserverContext))(@NonNull SessionObserverContext sessionObserverContext)
```

> [!CAUTION]
> **This method is deprecated.**   
> This library is no longer supported.

Called exactly once per session, when the `https://developer.android.com/reference/androidx/privacysandbox/ui/core/SandboxedUiAdapter.Session` associated with the session observer is created. `https://developer.android.com/reference/androidx/privacysandbox/ui/core/SessionObserver#onSessionOpened(androidx.privacysandbox.ui.core.SessionObserverContext)` contains data which will be constant for the lifetime of the UI session. The resources associated with the `https://developer.android.com/reference/androidx/privacysandbox/ui/core/SessionObserver#onSessionOpened(androidx.privacysandbox.ui.core.SessionObserverContext)` will be released when `https://developer.android.com/reference/androidx/privacysandbox/ui/core/SessionObserver#onSessionClosed()` is called.

### onUiContainerChanged

Added in [1.0.0-alpha17](https://developer.android.com/jetpack/androidx/releases/privacysandbox-ui#1.0.0-alpha17) Deprecated in [1.0.0-alpha17](https://developer.android.com/jetpack/androidx/releases/privacysandbox-ui#1.0.0-alpha17)

```
abstract void [onUiContainerChanged](https://developer.android.com/reference/androidx/privacysandbox/ui/core/SessionObserver#onUiContainerChanged(android.os.Bundle))(@NonNull Bundle uiContainerInfo)
```

> [!CAUTION]
> **This method is deprecated.**   
> This library is no longer supported.

Called when the UI container has changed its presentation state. Note that these updates will not be sent instantaneously, and will be throttled. This should not be used to react to UI changes on the client side as it is not sent in real time.