活动在使用画中画时泄漏了窗口

Posted

技术标签:

【中文标题】活动在使用画中画时泄漏了窗口【英文标题】:Activity has leaked window while using PiP 【发布时间】:2021-06-16 04:58:56 【问题描述】:

我的应用使用 exoplayer 显示视频流。在我使用/激活 Pip 之前,一切正常。在我将任何视频放入 Pip 并从后台堆栈返回上一个活动后(自动),当我按下任何按钮时,我得到:

WindowManager: android.view.WindowLeaked: Activity com.rcsrds.player.ui.main.MainActivity has leaked window DecorView@ff7d496[] that was originally added here

我在部分测试手机上收到此错误消息,但不是全部。如果我在 5 秒后按下任何按钮超过 1 次,我会得到 ANR(有时);我的应用不使用任何对话框

我确实有一个 ProgressBar。评论它,错误仍然出现。

LE:我的播放器是自定义视图。这应该是画中画的问题?

输入我使用的 Pip

   public void enterPictureInPicture(PictureInPictureParams nPipParams) 
       ActivityUtils.hideSystemUI(this.getWindow());
       if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) 
           enterPictureInPictureMode(nPipParams);
        else 
           //Toast.makeText(this,"Picture in Picture not availabe",Toast.LENGTH_LONG).show();
       
   

<activity
           android:name=".ui.main.MainActivity"
           android:configChanges="screenSize|smallestScreenSize|screenLayout"
           android:supportsPictureInPicture="true"
           android:excludeFromRecents="true"
           android:autoRemoveFromRecents="true"
          />




【问题讨论】:

【参考方案1】:

您缺少android:configChanges orientation 的推荐:

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

完整列表应该是。 android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"

PIP 不支持销毁 Activity。

您的 Activity 正在被破坏,因为它以纵向运行并且输入 PIP 会将其切换为横向。

也许您测试设备的其他时间已经在横向。

【讨论】:

以上是关于活动在使用画中画时泄漏了窗口的主要内容,如果未能解决你的问题,请参考以下文章

在多个窗口中使用 WPF WebBrowser 控件时发生内存泄漏

活动在显示 Toast 后泄漏窗口 [重复]

Android画中画比例视图

我的活动已泄漏窗口,我找不到解决方案

画中画 打开应用程序的新窗口并显示大量最近的任务

PiP 进入时避免活动娱乐