Anton
Anton

Reputation: 947

Android PiP mode and app life cycle

I am adding PiP Mode to my app and found a problem with life cycle. Official documentation says:"When your activity switches to PIP, the system places the activity in the paused state and calls the activity's onPause() method. Video playback should not be paused and should continue playing if the activity is paused while in PIP mode." But in my case I have the following order after entering PiP mode:

07-19 17:03:40.094 Enter PiP mode
07-19 17:03:40.193 OnPause(
07-19 17:03:40.780 OnStop()
07-19 17:03:40.788 OnDestroy()
07-19 17:03:40.927 OnCreate()
07-19 17:03:40.937 OnStart()
07-19 17:03:41.014 OnResume
07-19 17:03:41.024 OnPause()

what is wrong? After that I have a relaunched app in a small PiP window.

public void Pip_Click(View v) {

        if (android.os.Build.VERSION.SDK_INT >= 26) {
            //Trigger PiP mode
            try {
                Rational rational = new Rational(simpleExoPlayerView.getWidth(), simpleExoPlayerView.getHeight());

                PictureInPictureParams mParams = new PictureInPictureParams.Builder()
                                .setAspectRatio(rational)
                                .build();

                appendLog("enter PiP mode");
                enterPictureInPictureMode(mParams);

                setFullScreen();
            } catch (IllegalStateException e) {
                e.printStackTrace();
            }
        } else {
            Toast.makeText(MainActivity.this, "Not supported", Toast.LENGTH_SHORT).show();
        }

    }

from Manifest:

<activity
            android:name=".MainActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:supportsPictureInPicture="true"
            android:label="@string/app_name"
            android:launchMode="singleTask">

        </activity>

Upvotes: 1

Views: 2844

Answers (1)

Anton
Anton

Reputation: 947

Solved my problem by changing this:

<activity
            android:name=".MainActivity"
            android:resizeableActivity="true"
            android:configChanges="orientation|keyboardHidden|screenSize|smallestScreenSize|screenLayout"
            android:supportsPictureInPicture="true"
            android:label="@string/app_name"
            android:launchMode="singleTask">
        </activity>

Upvotes: 5

Related Questions