有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Youtube Api崩溃Youtube服务泄露了IntentReceiver

我用YoutubeApi构建了一个原生安卓应用程序。 有时当我从另一个活动返回到另一个活动时 对于youtubePlayer片段(YouTubePlayerSupportFragment),它会崩溃,并显示以下消息:

05-19 15:43:10.869 4009-4009/? E/ActivityThread: Service com.google.安卓.youtube.api.service.YouTubeService has leaked IntentReceiver vsi@26900cf that was originally registered here. Are you missing a call to unregisterReceiver()?
    安卓.app.IntentReceiverLeaked: Service com.google.安卓.youtube.api.service.YouTubeService has leaked IntentReceiver vsi@26900cf that was originally registered here. Are you missing a call to unregisterReceiver()?
        at 安卓.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:1333)
        at 安卓.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:1114)
        at 安卓.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1405)
        at 安卓.app.ContextImpl.registerReceiver(ContextImpl.java:1378)
        at 安卓.app.ContextImpl.registerReceiver(ContextImpl.java:1366)
        at 安卓.content.ContextWrapper.registerReceiver(ContextWrapper.java:603)
        at wyy.<init>(SourceFile:53)
        at wzg.get(SourceFile:32)
        at adzu.get(SourceFile:10)
        at hog.a(SourceFile:26)
        at hpb.a(SourceFile:881)
        at hnz.<init>(SourceFile:13)
        at com.google.安卓.apps.youtube.embeddedplayer.service.service.jar.ApiPlayerService.<init>(SourceFile:60)
        at com.google.安卓.apps.youtube.embeddedplayer.service.service.jar.ApiPlayerFactoryService$1.run(SourceFile:10)
        at 安卓.os.Handler.handleCallback(Handler.java:789)
        at 安卓.os.Handler.dispatchMessage(Handler.java:98)
        at 安卓.os.Looper.loop(Looper.java:164)
        at 安卓.app.ActivityThread.main(ActivityThread.java:6541)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.安卓.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
        at com.安卓.internal.os.ZygoteInit.main(ZygoteInit.java:767)
05-19 15:43:10.889 1960-1988/? W/Looper: Dispatch took 500ms on 安卓.ui, h=Handler (com.安卓.server.am.ActivityManagerService$UiHandler) {53d8b6e} cb=null msg=53
05-19 15:43:10.899 1960-3859/? D/EGL_emulation: eglMakeCurrent: 0xa0d2d900: ver 3 0 (tinfo 0x9e7e5580)
05-19 15:43:10.904 1436-1436/? D/SurfaceFlinger: duplicate layer name: changing Splash Screen com.example.galzaid.movies to Splash Screen com.example.galzaid.movies#1
05-19 15:43:10.908 4009-4009/? E/ActivityThread: Service com.google.安卓.youtube.api.service.YouTubeService has leaked IntentReceiver vsl@33574e2 that was originally registered here. Are you missing a call to unregisterReceiver()?
    安卓.app.IntentReceiverLeaked: Service com.google.安卓.youtube.api.service.YouTubeService has leaked IntentReceiver vsl@33574e2 that was originally registered here. Are you missing a call to unregisterReceiver()?
        at 安卓.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:1333)
        at 安卓.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:1114)
        at 安卓.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1405)
        at 安卓.app.ContextImpl.registerReceiver(ContextImpl.java:1378)
        at 安卓.app.ContextImpl.registerReceiver(ContextImpl.java:1366)
        at 安卓.content.ContextWrapper.registerReceiver(ContextWrapper.java:603)
        at vsj.<init>(SourceFile:21)
        at vsq.get(SourceFile:9)
        at wzg.get(SourceFile:31)
        at adzu.get(SourceFile:10)
        at hog.a(SourceFile:26)
        at hpb.a(SourceFile:881)
        at hnz.<init>(SourceFile:13)
        at com.google.安卓.apps.youtube.embeddedplayer.service.service.jar.ApiPlayerService.<init>(SourceFile:60)
        at com.google.安卓.apps.youtube.embeddedplayer.service.service.jar.ApiPlayerFactoryService$1.run(SourceFile:10)
        at 安卓.os.Handler.handleCallback(Handler.java:789)
        at 安卓.os.Handler.dispatchMessage(Handler.java:98)
        at 安卓.os.Looper.loop(Looper.java:164)
        at 安卓.app.ActivityThread.main(ActivityThread.java:6541)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.安卓.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
        at com.安卓.internal.os.ZygoteInit.main(ZygoteInit.java:767)

我听说我可能需要添加未注册接收器(广播接收器), 虽然我还没找到办法


共 (1) 个答案

  1. # 1 楼答案

    Youtube api文档似乎涵盖了解决方案:https://developers.google.com/youtube/android/player/reference/com/google/android/youtube/player/YouTubePlayerFragment

    “每当调用其onDestroyView()方法时,与此片段关联的YouTubePlayer将被释放。因此,您必须重新调用initialize(String,YouTubePlayer.OnInitializedListener)无论何时重新创建与此片段关联的活动,即使通过设置setRetainInstance(布尔值)在活动重新创建期间保留片段实例。"

    添加这一行有助于:

            frag.setRetainInstance(true);
    

    frag是我用于api的youtube片段