Picture in Picture Opens new window of the app and shows tons of recent tasks
Asked Answered
C

1

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..

Curule answered 11/2, 2021 at 3:52 Comment(1)
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: developer.android.com/guide/components/activities/… and developer.android.com/guide/components/activities/…Let
S
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()
        }
    }
Stoller answered 11/2, 2021 at 4:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.