# ContentPipCallback

Artifact: [androidx.core:core-pip](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/pip/contentpip/ContentPipCallback.kt+class:androidx.core.pip.contentpip.ContentPipCallback) Added in [1.0.0-alpha04](https://developer.android.com/jetpack/androidx/releases/core#1.0.0-alpha04)

*** ** * ** ***


```
public interface ContentPipCallback
```

<br />

*** ** * ** ***

A callback interface for managing the handoff of a content between the main activity and the Content PiP.

After registering `https://developer.android.com/reference/androidx/core/pip/contentpip/ContentPipCallback` via `https://developer.android.com/reference/androidx/core/pip/contentpip/package-summary#(androidx.activity.ComponentActivity).enablePipOnAppSwitch(androidx.core.pip.contentpip.ContentPipCallback)`, application can expect the callbacks in the following order

1. `https://developer.android.com/reference/androidx/core/pip/contentpip/ContentPipCallback#onInitContentPip()`, app can return the PiP eligibility

2. `https://developer.android.com/reference/androidx/core/pip/contentpip/ContentPipCallback#onPrepareContentPip()`, app prepares for the handoff

3. `https://developer.android.com/reference/androidx/core/pip/contentpip/ContentPipCallback#onAttachContentPip(androidx.activity.ComponentActivity)`, app attaches the content to the new Activity (that will enter PiP)

4. `https://developer.android.com/reference/androidx/core/pip/contentpip/ContentPipCallback#onFinishContentPip(kotlin.Boolean)`, app is notified that content PiP is finished

## Summary

| ### Public methods |
|---|---|
| `abstract void` | `https://developer.android.com/reference/androidx/core/pip/contentpip/ContentPipCallback#onAttachContentPip(androidx.activity.ComponentActivity)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/activity/ComponentActivity pipActivity)` Called once the proxy PiP Activity is ready. |
| `abstract void` | `https://developer.android.com/reference/androidx/core/pip/contentpip/ContentPipCallback#onFinishContentPip(kotlin.Boolean)(boolean isDismissed)` Called when the PiP task is finishing or the enter PiP attempt is failed. |
| `abstract boolean` | `https://developer.android.com/reference/androidx/core/pip/contentpip/ContentPipCallback#onInitContentPip()()` Called before attempting to start the Content PiP solution. |
| `abstract boolean` | `https://developer.android.com/reference/androidx/core/pip/contentpip/ContentPipCallback#onPrepareContentPip()()` Called on the main Activity to prepare for the handoff (e.g., detaching a Player from its View). |

## Public methods

### onAttachContentPip

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

```
abstract void onAttachContentPip(@NonNull ComponentActivity pipActivity)
```

Called once the proxy PiP Activity is ready. The app should attach its content (e.g., a Player) to this new `https://developer.android.com/reference/androidx/core/pip/contentpip/ContentPipCallback#onAttachContentPip(androidx.activity.ComponentActivity)`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/activity/ComponentActivity pipActivity` | The new Activity serving as the PiP container. |

### onFinishContentPip

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

```
abstract void onFinishContentPip(boolean isDismissed)
```

Called when the PiP task is finishing or the enter PiP attempt is failed.

For instance, a video app can use `https://developer.android.com/reference/androidx/core/pip/contentpip/ContentPipCallback#onFinishContentPip(kotlin.Boolean)` to determine if it needs to stop playback. This is `true` when the user dismisses or closes the PiP, and `false` when the user expands the PiP to full-screen mode.

| Parameters |
|---|---|
| `boolean isDismissed` | whether the PiP task is explicitly dismissed by the user. |

### onInitContentPip

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

```
abstract boolean onInitContentPip()
```

Called before attempting to start the Content PiP solution.

| Returns |
|---|---|
| `boolean` | `true` if the application is eligible to enter PiP. If `false` is returned, the PiP flow is canceled. |

### onPrepareContentPip

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

```
abstract boolean onPrepareContentPip()
```

Called on the main Activity to prepare for the handoff (e.g., detaching a Player from its View).

| Returns |
|---|---|
| `boolean` | `true` if the handoff is successful on the main Activity. If `false` is returned, the PiP flow is canceled. |