Error: YouTubeService leaked IntentReceiver ... Do you miss calling unregisterReceiver ()?

I use the YoutubeServie API to play youtube videos in an Android app. However, when I quit my activity, I found that the crash log is displayed below, even my application is still running.

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) 

None of the code is from my application, but they are all in the library. I did not register the receiver in my code, so I can not unregister in my fragment that works with youtubeservice.

I think the problem is similar to https://groups.google.com/forum/#!topic/android-developers/6gzpwkaRgoE , but there was no answer. Any idea how to get rid of this internal youtube.api.service failure?

+5
source share
2 answers

Even if you do not manually register the registrar, an activity can register it in order to use it in any way for the current activity. I think you will need to call the unregisterReceiver () method on onPause () .

Remember that onDestroy () and onStop () cannot be called. If onPause () is called, then the action is no longer in the foreground.

OnStop ():

Called when the user is no longer displayed. Then you will get either onRestart (), onDestroy (), or nothing, depending on the later activity of the user. Please note that this method can never be called in situations with low memory, when the system does not have enough memory to keep your process active after calling the onPause () method.

For more information, here is the link: http://developer.android.com/reference/android/app/Activity.html#onStop%28%29

Fortunately, I also found some stackoverflow elements that you can find:

Hope this helps.

0
source

I solved this:

In manifest.xml, declare something like this.

 <activity android:name=".YouTubeActivity" android:configChanges="keyboardHidden|orientation|screenSize" android:screenOrientation="landscape" android:theme="@style/AppTheme.NoActionBar" /> 
0
source

Source: https://habr.com/ru/post/1244032/


All Articles