android - 服务com.google.android.youtube.api.service.YouTubeService泄漏了IntentReceiver uds @ 5fa5135

标签 android memory-leaks youtube youtube-api android-youtube-api

每次我从后堆栈中删除YouTubePlayerSupportFragment时,都会在logcat中收到以下错误:

06-12 02:08:46.937 8805-8805/ D/GA_DEBUG: Event_category:VideoContent-Portrait-This artist uses unique methods to paint his pottery action:play label:youtube {&el=youtube, &ec=VideoContent-Portrait-This artist uses unique methods to paint his pottery, &t=event, &ea=play, &cd6=online}
06-12 02:08:46.945 10194-10194/? E/ActivityThread: Service com.google.android.youtube.api.service.YouTubeService has leaked IntentReceiver uds@5fa5135 that was originally registered here. Are you missing a call to unregisterReceiver()?                                                   
android.app.IntentReceiverLeaked: Service com.google.android.youtube.api.service.YouTubeService has leaked IntentReceiver uds@5fa5135 that was originally registered here. Are you missing a call to unregisterReceiver()?
    at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:946)
    at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:742)
    at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1188)
    at android.app.ContextImpl.registerReceiver(ContextImpl.java:1168)
    at android.app.ContextImpl.registerReceiver(ContextImpl.java:1162)
    at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:555)
    at udq.<init>(SourceFile:21)
    at udx.get(SourceFile:9)
    at vkq.get(SourceFile:31)
    at aces.get(SourceFile:10)
    at hog.a(SourceFile:26)
    at hpb.a(SourceFile:883)
    at hnz.<init>(SourceFile:13)
    at com.google.android.apps.youtube.embeddedplayer.service.service.jar.ApiPlayerService.<init>(SourceFile:60)
    at com.google.android.apps.youtube.embeddedplayer.service.service.jar.ApiPlayerFactoryService$1.run(SourceFile:10)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:152)
    at android.app.ActivityThread.main(ActivityThread.java:5497)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
06-12 02:08:46.968 10194-10194/? E/ActivityThread: Service com.google.android.youtube.api.service.YouTubeService has leaked IntentReceiver udp@a7bd896 that was originally registered here. Are you missing a call to unregisterReceiver()?
android.app.IntentReceiverLeaked: Service com.google.android.youtube.api.service.YouTubeService has leaked IntentReceiver udp@a7bd896 that was originally registered here. Are you missing a call to unregisterReceiver()?
   at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:946)
   at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:742)
   at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1188)
   at android.app.ContextImpl.registerReceiver(ContextImpl.java:1168)
   at android.app.ContextImpl.registerReceiver(ContextImpl.java:1162)
   at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:555)
   at vki.<init>(SourceFile:53)
   at vkq.get(SourceFile:32)
   at aces.get(SourceFile:10)
   at hog.a(SourceFile:26)
   at hpb.a(SourceFile:883)
   at hnz.<init>(SourceFile:13)
   at com.google.android.apps.youtube.embeddedplayer.service.service.jar.ApiPlayerService.<init>(SourceFile:60)
   at com.google.android.apps.youtube.embeddedplayer.service.service.jar.ApiPlayerFactoryService$1.run(SourceFile:10)
   at android.os.Handler.handleCallback(Handler.java:739)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:152)
   at android.app.ActivityThread.main(ActivityThread.java:5497)
   at java.lang.reflect.Method.invoke(Native Method)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
06-12 02:08:47.015 8805-8805/I/ResourcesManager: isUpToDate /data/app/com.google.android.youtube-1/base.apk: true

我做错了什么?在删除片段之前,我确实将所有资源设置为null,并在播放器实例上调用了release(),但是此日志仍然存在。

最佳答案

在尝试了多种在项目中使用Youtube播放器片段的方法之后,我们在回收器 View 中显示了视频列表,并且每个视频都可以就地播放(当然,一次播放一次)。

仅管理适当的生命周期(将片段从一个地方移到另一个地方时调用发布)才有效,直到您快速执行,并且如果您碰巧尝试同时播放2个视频,则会发生上述问题(即,内部youtube sdk会泄漏一些触感消息队列中的事件)

,因此我们不会为每个视频替换youtube片段,而是仅创建一个片段实例,并在应用中的所有位置重复使用它,并且如果 Activity 生命周期事件(在暂停/停止或处于已保存实例状态时被调用),则我们释放片段然后在简历上,我们再次创建该YouTube片段的单个 Activity 实例

这种方法实际上已经解决了上述问题,并且https://issuetracker.google.com/issues/78370483

关于android - 服务com.google.android.youtube.api.service.YouTubeService泄漏了IntentReceiver uds @ 5fa5135,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44488780/

相关文章:

javascript - YouTube 视频在隐藏和显示其容器 div 时重新启动

jquery - 如何使用jQuery从URL显示来自youtube的视频?

android - MediaPlayer 视频大小代号?

c# - Xamarin.forms - Masterdetailpage : System. Reflection.TargetInvocationException:调用目标引发了异常

android - 如何在 ListView 中添加原生广告?

Java:如何跟踪/监视 CMS 垃圾收集器的 GC 时间?

c# - 通过YouTube API访问“喜欢”或“不喜欢”功能

android - 我应该使用 Camera2 还是 Camera APIs for Android?

c++ - 递归 C++ 调用中的内存分配

python - 如何分析库的大小