错误:YouTubeService泄露了IntentReceiver.您是否错过了对unregisterReceiver



我使用YoutubeServie API在我的Android应用程序中播放youtube视频。但是,当我退出活动时,我发现显示以下崩溃日志,即使我的应用程序仍然可以运行。

02-28 15:54:02.081 20374-20374/? E/ActivityThread: Service com.google.android.youtube.api.service.YouTubeService has leaked IntentReceiver com.google.android.libraries.youtube.player.audiofocus.HeadsetPlugReceiver@a843e7c 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 com.google.android.libraries.youtube.player.audiofocus.HeadsetPlugReceiver@a843e7c that was originally registered here. Are you missing a call to unregisterReceiver()?
                                                       at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:898)
                                                       at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:699)
                                                       at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1637)
                                                       at android.app.ContextImpl.registerReceiver(ContextImpl.java:1617)
                                                       at android.app.ContextImpl.registerReceiver(ContextImpl.java:1611)
                                                       at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:488)
                                                       at com.google.android.libraries.youtube.player.service.PlaybackService.<init>(PlaybackService.java:5034)
                                                       at com.google.android.libraries.youtube.player.PlayerInjector$12.create(PlayerInjector.java:1602)
                                                       at com.google.android.libraries.youtube.common.util.Lazy.get(Lazy.java:136)
                                                       at com.google.android.libraries.youtube.player.PlayerInjector.getPlaybackService(PlayerInjector.java:575)
                                                       at com.google.android.apps.youtube.api.ApiPlayer.moveToForeground(ApiPlayer.java:493)
                                                       at com.google.android.apps.youtube.api.ApiPlayer.<init>(ApiPlayer.java:150)
                                                       at com.google.android.apps.youtube.api.service.jar.ApiPlayerService.<init>(ApiPlayerService.java:131)
                                                       at com.google.android.apps.youtube.api.service.jar.ApiPlayerFactoryService$1.run(ApiPlayerFactoryService.java:86)
                                                       at android.os.Handler.handleCallback(Handler.java:739)
                                                       at android.os.Handler.dispatchMessage(Handler.java:95)
                                                       at android.os.Looper.loop(Looper.java:135)
                                                       at android.app.ActivityThread.main(ActivityThread.java:5221)
                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                       at java.lang.reflect.Method.invoke(Method.java:372)
                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
02-28 15:54:02.088 20374-20374/? E/ActivityThread: Service com.google.android.youtube.api.service.YouTubeService has leaked IntentReceiver com.google.android.libraries.youtube.player.audiofocus.AudioBecomingNoisyReceiver@379c216f 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 com.google.android.libraries.youtube.player.audiofocus.AudioBecomingNoisyReceiver@379c216f that was originally registered here. Are you missing a call to unregisterReceiver()?
                                                       at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:898)
                                                       at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:699)
                                                       at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1637)
                                                       at android.app.ContextImpl.registerReceiver(ContextImpl.java:1617)
                                                       at android.app.ContextImpl.registerReceiver(ContextImpl.java:1611)
                                                       at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:488)
                                                       at com.google.android.libraries.youtube.player.service.PlaybackService.<init>(PlaybackService.java:4043)
                                                       at com.google.android.libraries.youtube.player.PlayerInjector$12.create(PlayerInjector.java:1602)
                                                       at com.google.android.libraries.youtube.common.util.Lazy.get(Lazy.java:136)
                                                       at com.google.android.libraries.youtube.player.PlayerInjector.getPlaybackService(PlayerInjector.java:575)
                                                       at com.google.android.apps.youtube.api.ApiPlayer.moveToForeground(ApiPlayer.java:493)
                                                       at com.google.android.apps.youtube.api.ApiPlayer.<init>(ApiPlayer.java:150)
                                                       at com.google.android.apps.youtube.api.service.jar.ApiPlayerService.<init>(ApiPlayerService.java:131)
                                                       at com.google.android.apps.youtube.api.service.jar.ApiPlayerFactoryService$1.run(ApiPlayerFactoryService.java:86)
                                                       at android.os.Handler.handleCallback(Handler.java:739)
                                                       at android.os.Handler.dispatchMessage(Handler.java:95)
                                                       at android.os.Looper.loop(Looper.java:135)
                                                       at android.app.ActivityThread.main(ActivityThread.java:5221)
                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                       at java.lang.reflect.Method.invoke(Method.java:372)
                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

没有一个代码来自我的应用程序,但都在库中。我没有在我的代码中注册任何接收器,因此无法在我的片段中取消注册任何与 youtubeservice 一起使用的内容。

我认为这个问题与 https://groups.google.com/forum/#!topic/android-developers/6gzpwkaRgoE 相似,但没有给出答案。知道如何摆脱youtube.api.service的内部崩溃吗?

即使您不手动注册任何接收方,活动也可以注册它以以某种方式在当前活动上使用它。我认为你应该需要在onPause()上调用unregisterReceiver()方法。

请注意,onDestroy() 和 onStop() 不能保证被调用。如果将调用 onPause(),则活动不再位于前台。

OnStop():

当用户不再可见时调用。接下来,您将收到onRestart(),onDestroy()或什么都不接收,具体取决于以后的用户活动。 请注意,在内存不足的情况下,系统没有足够的内存来保持活动的进程在调用其 onPause() 方法后运行,则可能永远不会调用此方法。

有关更多信息,请访问以下链接:http://developer.android.com/reference/android/app/Activity.html#onStop%28%29

幸运的是,我还发现了一些可以参考的堆栈溢出项目:

  • 活动泄露了最初在此处注册的IntentReceiver。您是否错过了取消注册接收器()的调用?
  • 无法在我的安卓应用程序中播放YouTube视频
  • 您是否错过了对unregisterReceiver()的调用?

我希望这会有所帮助。

相关内容

  • 没有找到相关文章

最新更新