# PrimarySessionStateCallback

# PrimarySessionStateCallback

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySessionStateCallback "View this page in Kotlin")\|Java

<br />

```
@RequiresApi(value = 26) interface PrimarySessionStateCallback extends SessionStateCallback
```

<br />

*** ** * ** ***

Clients of Sessions should implement`PrimarySessionStateCallback`to receive notifications of Session state changes when acting as the Primary for a Shared Session.

Provide your implementation in[Sessions.shareSession](https://developer.android.com/reference/com/google/ambient/crossdevice/sessions/Sessions#shareSession(com.google.ambient.crossdevice.sessions.SessionId,com.google.ambient.crossdevice.wakeup.StartComponentRequest,kotlin.collections.List,com.google.ambient.crossdevice.sessions.PrimarySessionStateCallback)).

## Summary

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          ### Public methods                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          ||
|-----------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `abstract void` | [onParticipantDeparted](https://developer.android.com/reference/com/google/ambient/crossdevice/sessions/PrimarySessionStateCallback#onParticipantDeparted(com.google.ambient.crossdevice.sessions.SessionId,com.google.ambient.crossdevice.sessions.SessionParticipant))`(` ` @`[NonNull](https://developer.android.com/reference/androidx/annotation/NonNull)` `[SessionId](https://developer.android.com/reference/com/google/ambient/crossdevice/sessions/SessionId)` sessionId,` ` @`[NonNull](https://developer.android.com/reference/androidx/annotation/NonNull)` `[SessionParticipant](https://developer.android.com/reference/com/google/ambient/crossdevice/sessions/SessionParticipant)` participant` `)` Called when a secondary leaves the specified session.                                                                                                                                                                                                                                                                                                          |
| `abstract void` | [onParticipantJoined](https://developer.android.com/reference/com/google/ambient/crossdevice/sessions/PrimarySessionStateCallback#onParticipantJoined(com.google.ambient.crossdevice.sessions.SessionId,com.google.ambient.crossdevice.sessions.SessionParticipant))`(` ` @`[NonNull](https://developer.android.com/reference/androidx/annotation/NonNull)` `[SessionId](https://developer.android.com/reference/com/google/ambient/crossdevice/sessions/SessionId)` sessionId,` ` @`[NonNull](https://developer.android.com/reference/androidx/annotation/NonNull)` `[SessionParticipant](https://developer.android.com/reference/com/google/ambient/crossdevice/sessions/SessionParticipant)` participant` `)` Called when a secondary joins the specified session.                                                                                                                                                                                                                                                                                                               |
| `abstract void` | [onPrimarySessionCleanup](https://developer.android.com/reference/com/google/ambient/crossdevice/sessions/PrimarySessionStateCallback#onPrimarySessionCleanup(com.google.ambient.crossdevice.sessions.SessionId))`(@`[NonNull](https://developer.android.com/reference/androidx/annotation/NonNull)` `[SessionId](https://developer.android.com/reference/com/google/ambient/crossdevice/sessions/SessionId)` sessionId)` Called when a[PrimarySession](https://developer.android.com/reference/com/google/ambient/crossdevice/sessions/PrimarySession)has no active secondaries (and no joins in progress).                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `abstract void` | [onShareFailureWithParticipant](https://developer.android.com/reference/com/google/ambient/crossdevice/sessions/PrimarySessionStateCallback#onShareFailureWithParticipant(com.google.ambient.crossdevice.sessions.SessionId,com.google.ambient.crossdevice.sessions.SessionException,com.google.ambient.crossdevice.sessions.SessionParticipant))`(` ` @`[NonNull](https://developer.android.com/reference/androidx/annotation/NonNull)` `[SessionId](https://developer.android.com/reference/com/google/ambient/crossdevice/sessions/SessionId)` sessionId,` ` @`[NonNull](https://developer.android.com/reference/androidx/annotation/NonNull)` `[SessionException](https://developer.android.com/reference/com/google/ambient/crossdevice/sessions/SessionException)` exception,` ` @`[NonNull](https://developer.android.com/reference/androidx/annotation/NonNull)` `[SessionParticipant](https://developer.android.com/reference/com/google/ambient/crossdevice/sessions/SessionParticipant)` participant` `)` Called when share cannot complete with a specific participant. |
| `abstract void` | [onShareInitiated](https://developer.android.com/reference/com/google/ambient/crossdevice/sessions/PrimarySessionStateCallback#onShareInitiated(com.google.ambient.crossdevice.sessions.SessionId,kotlin.Int))`(` ` @`[NonNull](https://developer.android.com/reference/androidx/annotation/NonNull)` `[SessionId](https://developer.android.com/reference/com/google/ambient/crossdevice/sessions/SessionId)` sessionId,` ` int numPotentialParticipants` `)` Called when a set of participants is provided with a Share request from this Primary.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |

## Public methods

### onParticipantDeparted

```
abstract void onParticipantDeparted(
    @NonNull SessionId sessionId,
    @NonNull SessionParticipant participant
)
```

Called when a secondary leaves the specified session.  

### onParticipantJoined

```
abstract void onParticipantJoined(
    @NonNull SessionId sessionId,
    @NonNull SessionParticipant participant
)
```

Called when a secondary joins the specified session.  

### onPrimarySessionCleanup

```
abstract void onPrimarySessionCleanup(@NonNull SessionId sessionId)
```

Called when a[PrimarySession](https://developer.android.com/reference/com/google/ambient/crossdevice/sessions/PrimarySession)has no active secondaries (and no joins in progress). After this call, continued use of the[PrimarySession](https://developer.android.com/reference/com/google/ambient/crossdevice/sessions/PrimarySession)will return[SessionException](https://developer.android.com/reference/com/google/ambient/crossdevice/sessions/SessionException)on all method calls because it is no longer valid.  

### onShareFailureWithParticipant

```
abstract void onShareFailureWithParticipant(
    @NonNull SessionId sessionId,
    @NonNull SessionException exception,
    @NonNull SessionParticipant participant
)
```

Called when share cannot complete with a specific participant. Failure reason described by`exception`. Called on the originating device.  

### onShareInitiated

```
abstract void onShareInitiated(
    @NonNull SessionId sessionId,
    int numPotentialParticipants
)
```

Called when a set of participants is provided with a Share request from this Primary. This method will be called once for each application call to[Sessions.shareSession](https://developer.android.com/reference/com/google/ambient/crossdevice/sessions/Sessions#shareSession(com.google.ambient.crossdevice.sessions.SessionId,com.google.ambient.crossdevice.wakeup.StartComponentRequest,kotlin.collections.List,com.google.ambient.crossdevice.sessions.PrimarySessionStateCallback)).