# PrimarySessionStateCallback

# PrimarySessionStateCallback

*** ** * ** ***

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

<br />

```
@RequiresApi(value = 26) interface PrimarySessionStateCallback : 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/kotlin/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 functions                                                                                                                                                                                                                                                                                                                                                                                                                                                      ||
|--------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit](https://developer.android.com/reference/kotlin/kotlin/Unit) | [onParticipantDeparted](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySessionStateCallback#onParticipantDeparted(com.google.ambient.crossdevice.sessions.SessionId,com.google.ambient.crossdevice.sessions.SessionParticipant))`(` ` sessionId: `[SessionId](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SessionId)`,` ` participant: `[SessionParticipant](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SessionParticipant) `)` Called when a secondary leaves the specified session.                                                                                                                                                                                                                                |
| [Unit](https://developer.android.com/reference/kotlin/kotlin/Unit) | [onParticipantJoined](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySessionStateCallback#onParticipantJoined(com.google.ambient.crossdevice.sessions.SessionId,com.google.ambient.crossdevice.sessions.SessionParticipant))`(` ` sessionId: `[SessionId](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SessionId)`,` ` participant: `[SessionParticipant](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SessionParticipant) `)` Called when a secondary joins the specified session.                                                                                                                                                                                                                                     |
| [Unit](https://developer.android.com/reference/kotlin/kotlin/Unit) | [onPrimarySessionCleanup](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySessionStateCallback#onPrimarySessionCleanup(com.google.ambient.crossdevice.sessions.SessionId))`(sessionId: `[SessionId](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SessionId)`)` Called when a[PrimarySession](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySession)has no active secondaries (and no joins in progress).                                                                                                                                                                                                                                                                                                           |
| [Unit](https://developer.android.com/reference/kotlin/kotlin/Unit) | [onShareFailureWithParticipant](https://developer.android.com/reference/kotlin/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))`(` ` sessionId: `[SessionId](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SessionId)`,` ` exception: `[SessionException](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SessionException)`,` ` participant: `[SessionParticipant](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SessionParticipant) `)` Called when share cannot complete with a specific participant. |
| [Unit](https://developer.android.com/reference/kotlin/kotlin/Unit) | [onShareInitiated](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/PrimarySessionStateCallback#onShareInitiated(com.google.ambient.crossdevice.sessions.SessionId,kotlin.Int))`(sessionId: `[SessionId](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SessionId)`, numPotentialParticipants: `[Int](https://developer.android.com/reference/kotlin/kotlin/Int)`)` Called when a set of participants is provided with a Share request from this Primary.                                                                                                                                                                                                                                                                                                                    |

## Public functions

### onParticipantDeparted

```
fun onParticipantDeparted(
    sessionId: SessionId,
    participant: SessionParticipant
): Unit
```

Called when a secondary leaves the specified session.  

### onParticipantJoined

```
fun onParticipantJoined(
    sessionId: SessionId,
    participant: SessionParticipant
): Unit
```

Called when a secondary joins the specified session.  

### onPrimarySessionCleanup

```
fun onPrimarySessionCleanup(sessionId: SessionId): Unit
```

Called when a[PrimarySession](https://developer.android.com/reference/kotlin/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/kotlin/com/google/ambient/crossdevice/sessions/PrimarySession)will return[SessionException](https://developer.android.com/reference/kotlin/com/google/ambient/crossdevice/sessions/SessionException)on all method calls because it is no longer valid.  

### onShareFailureWithParticipant

```
fun onShareFailureWithParticipant(
    sessionId: SessionId,
    exception: SessionException,
    participant: SessionParticipant
): Unit
```

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

### onShareInitiated

```
fun onShareInitiated(sessionId: SessionId, numPotentialParticipants: Int): Unit
```

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/kotlin/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)).