我正在将画中画模式添加到我的应用程序,发现生命周期存在问题。官方文档说:“当您的活动切换到PIP时,系统会将活动置于暂停状态并调用该活动的onPause()方法。视频播放不应暂停,并且如果在PIP模式下暂停该活动,则视频播放应该继续播放。 ”但就我而言,进入画中画模式后,我的命令如下:
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()
怎么了?之后,我会在一个小的PiP窗口中重新启动应用程序。
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();
}
}
来自清单:
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:supportsPictureInPicture="true"
android:label="@string/app_name"
android:launchMode="singleTask">
</activity>
答案 0 :(得分:1)
通过更改此方法解决了我的问题:
<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>