5

I am playing my videos in PIP mode when on Pressback button. Everything is fine. video playing perfectly. navigation etc. But problem is when i Close PIP mode. There is new window created on my recent apps window. IMAGE. See those white windows those are left by pip mode when i click pip mode close button.

Is there any way to solve this and close activity when I close the pip mode please help..

Rajan Kali
  • 12,627
  • 3
  • 25
  • 37
  • looks like whenever you closing the PIP mode, a new instance of the activity is created. You can modify the launch mode to fix this problem. refer: https://developer.android.com/guide/components/activities/tasks-and-back-stack#ManifestForTasks and https://developer.android.com/guide/components/activities/recents#attr-doclaunch – Alpha 1 Feb 11 '21 at 04:02

1 Answers1

6

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()
        }
    }
Rajan Kali
  • 12,627
  • 3
  • 25
  • 37