Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to start picture in picture mode instead of going to background? Like youtube premium

I know how to enable picture-in-picture mode itself when an app runs normally but the problem is that I want to activate it when the app goes to background mode i.e. on activity pause.
A good example of such behavior is YouTube premium app on android. When a video is playing and a user taps "home" button the video just keeps on playing in PIP mode.
I tried to implement LifecycleObserver and launch picture-in-picture mode from its "onPause" callback. But it says "activity must be resumed to enter picture-in-picture".
I took a look inside onPause method and it’s implemented in a way that super.onPause() must be called first, so I can’t just override it and not to call "super".

Does anyone have any suggestion on how implement this Youtube-like behavior?
p.s. I’ve googled a lot before asking this

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The docs provide an example for this:

@Override
public void onUserLeaveHint () {
    if (iWantToBeInPipModeNow()) {
        enterPictureInPictureMode();
    }
}

https://developer.android.com/guide/topics/ui/picture-in-picture#pip_button

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading