对于我的 android 应用程序,当用户播放视频时,新 Activity (VideoPlay) 将以 pip 模式启动。
list (视频播放)
<activity
android:name=".PlayVideo"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:launchMode="singleTask"
android:theme="@style/AppTheme.NoActionBar"
tools:ignore="LockedOrientationActivity"
android:supportsPictureInPicture="true"
android:configChanges=
"screenSize|smallestScreenSize|screenLayout|orientation"/>
问题是当我点击 pip 屏幕的关闭按钮“X”时,我的应用程序的一个新实例被创建。
如何处理这个问题?谢谢
最佳答案
这不是您应用的另一个实例,而是包含您的 PlayVideo
Activity 的不同任务。为防止在最近屏幕上显示您的 Activity ,您可以在 PlayVideo
Activity 的 list 属性中添加 android:excludeFromRecents="true"
。
此外,如果您以某种方式强制关闭您的 PlayVideo
Activity ,而不是用户交互(如 backpress),您可能希望调用 finishAndRemoveTask()
而不仅仅是 finish()
因为调用 finish()
不会从最近的 Activity 中删除您的 Activity 。
关于java - Android:以画中画模式播放视频(点击关闭按钮时多次出现),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61443950/