本文介绍了Youtube Api崩溃,YouTubeService泄漏了IntentReceiver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用YoutubeApi构建了本地Android应用。
有时,当我使用youtubePlayer片段(YouTubePlayerSupportFragment)从另一个活动回压到活动
时,它崩溃并显示以下消息:

I have built a native android app using YoutubeApi.Sometimes when I backpress from another activity to the activity with the youtubePlayer fragment (YouTubePlayerSupportFragment) it crashes with the following message:

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),
尽管我还没有找到一种方法。

I have heared I might need to add unregisterReciver(Broadcast Reciver),Although I haven't found a way to do it.

推荐答案

Youtube api的文件似乎涵盖了这样的说法:

Youtube api documantation seem to cover the soloution: https://developers.google.com/youtube/android/player/reference/com/google/android/youtube/player/YouTubePlayerFragment

与此片段关联的YouTubePlayer只要其onDestroyView()方法就会被释放叫做。因此,每当与该片段相关联的活动被重新创建时,即使通过设置setRetainInstance(boolean)保留活动重新创建片段实例,您都必须重新调用initialize(String,YouTubePlayer.OnInitializedListener)。

"The YouTubePlayer associated with this fragment will be released whenever its onDestroyView() method is called. You will therefore have to re-call initialize(String, YouTubePlayer.OnInitializedListener) whenever the activity associated with this fragment is recreated, even if the fragment instance is retained across activity re-creation by setting setRetainInstance(boolean)."

添加以下行有助于:

        frag.setRetainInstance(true);

frag是我用于api的youtube片段。

frag is the youtube fragment I used for the api.

这篇关于Youtube Api崩溃,YouTubeService泄漏了IntentReceiver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 13:45