Try to use below configuration in Manifest for your Activity to avoid multiple instances
<activity
android:name=".view.activities.PlayerActivity"
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation|uiMode"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:resizeableActivity="false"
android:taskAffinity=".PlayerActivity"
android:supportsPictureInPicture="true"
android:windowSoftInputMode="adjustResize"
tools:targetApi="n"/>
And below approach to finish the activity when closed in PIP mode
var isInPipMode: Boolean = false
override fun onPictureInPictureModeChanged(
isInPictureInPictureMode: Boolean,
newConfig: Configuration?
) {
super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig)
isInPipMode = isInPictureInPictureMode
}
override fun onStop() {
super.onStop()
if(isInPipMode){
finish()
}
}