androidx.core.pip.contentpip


Interfaces

ContentPipCallback

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

Classes

ContentPipToken

Token holding the registered callbacks and observers used to manage Picture-in-Picture (PiP) for content inside a ComponentActivity.

Extension functions summary

Unit

Disables entering PiP on app switch for this Activity with Content PiP.

ContentPipToken

Enables entering PiP on app switch for this Activity with Content PiP.

Extension functions

ComponentActivity.disablePipOnAppSwitch

fun ComponentActivity.disablePipOnAppSwitch(
    contentPipToken: ContentPipToken
): Unit

Disables entering PiP on app switch for this Activity with Content PiP.

This method unregisters the listeners and observers that were added by enablePipOnAppSwitch. It restores the original window callback and stops monitoring lifecycle and exit hints.

Threading: This method must be called on the main thread of your application.

Parameters
contentPipToken: ContentPipToken

The token returned by enablePipOnAppSwitch.

ComponentActivity.enablePipOnAppSwitch

fun ComponentActivity.enablePipOnAppSwitch(callback: ContentPipCallback): ContentPipToken

Enables entering PiP on app switch for this Activity with Content PiP.

This API hooks into standard Activity exit hints to trigger a fallback PiP pipeline when native Auto-Enter is suppressed by the OS (e.g. on Quick Switch).

It also automatically monitors the Activity lifecycle and user interactions to "pull back" the player and terminate the fallback task when the user returns to the app.

It is recommended to call this method from ComponentActivity.onCreate, if it is called multiple times, only the last ContentPipCallback is effective.

Threading: This callback is strictly tied to the UI toolkit and will always be executed synchronously on the main thread of your application.

Parameters
callback: ContentPipCallback

The callback to manage handoff between tasks.

Returns
ContentPipToken

ContentPipToken that caller can pass to disablePipOnAppSwitch.