【问题标题】:Youtube Api Crashed, YouTubeService has leaked IntentReceiverYoutube Api Crashed,YouTubeService 泄露 IntentReceiver
【发布时间】:2018-10-29 19:42:34
【问题描述】:

我已经使用 YoutubeApi 构建了一个原生 android 应用程序。 有时当我从另一个活动回退到该活动时 使用 youtubePlayer 片段 (YouTubePlayerSupportFragment) 它会崩溃并显示以下消息:

05-19 15:43:10.869 4009-4009/? E/ActivityThread: Service com.google.android.youtube.api.service.YouTubeService has leaked IntentReceiver vsi@26900cf 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 vsi@26900cf that was originally registered here. Are you missing a call to unregisterReceiver()?
        at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:1333)
        at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:1114)
        at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1405)
        at android.app.ContextImpl.registerReceiver(ContextImpl.java:1378)
        at android.app.ContextImpl.registerReceiver(ContextImpl.java:1366)
        at android.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.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:789)
        at android.os.Handler.dispatchMessage(Handler.java:98)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6541)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
05-19 15:43:10.889 1960-1988/? W/Looper: Dispatch took 500ms on android.ui, h=Handler (com.android.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.android.youtube.api.service.YouTubeService has leaked IntentReceiver vsl@33574e2 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 vsl@33574e2 that was originally registered here. Are you missing a call to unregisterReceiver()?
        at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:1333)
        at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:1114)
        at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1405)
        at android.app.ContextImpl.registerReceiver(ContextImpl.java:1378)
        at android.app.ContextImpl.registerReceiver(ContextImpl.java:1366)
        at android.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.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:789)
        at android.os.Handler.dispatchMessage(Handler.java:98)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6541)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

我听说我可能需要添加 unregisterReciver(Broadcast Reciver), 虽然我还没有找到办法。

【问题讨论】:

    标签: java android youtube-api broadcastreceiver


    【解决方案1】:

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

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

    添加这一行有帮助:

            frag.setRetainInstance(true);
    

    frag 是我用于 api 的 youtube 片段。

    【讨论】:

      猜你喜欢
      • 2012-04-04
      • 2012-07-03
      • 2016-06-11
      • 2018-01-26
      • 1970-01-01
      • 2018-11-15
      • 1970-01-01
      • 2012-10-18
      • 1970-01-01
      相关资源
      最近更新 更多