我是一个新手Android“程序员”,我试图找到这个错误的答案,但没有运气。有一些一半的答案,但没有什么可以建议在我独特的情况下更准确地做什么。
关闭 YoutubePlayer 活动时会出现此错误。看来我应该注销一个接收器,可能在 onPause() 中......但我该怎么做,也许更重要的是,应该注销哪个接收器?
这是我的日志:
06-06 02:17:31.781 26887-26887/? E/ActivityThread: Service com.google.android.youtube.api.service.YouTubeService has leaked IntentReceiver adez@e1c9513 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 adez@e1c9513 that was originally registered here. Are you missing a call to unregisterReceiver()?
at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:923)
at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:724)
at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1182)
at android.app.ContextImpl.registerReceiver(ContextImpl.java:1162)
at android.app.ContextImpl.registerReceiver(ContextImpl.java:1156)
at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:564)
at adex.<init>(SourceFile:18)
at adfe.get(SourceFile:15)
at aerr.get(SourceFile:46)
at aoqy.get(SourceFile:11)
at lad.h(SourceFile:148)
at addo.get(SourceFile:9)
at aoqy.get(SourceFile:11)
at laf.a(SourceFile:7)
at kyp.<init>(SourceFile:10)
at com.google.android.apps.youtube.embeddedplayer.service.service.jar.ApiPlayerService.<init>(SourceFile:48)
at com.google.android.apps.youtube.embeddedplayer.service.service.jar.ApiPlayerFactoryService$1.run(SourceFile:4)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5441)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)
添加一些代码。试图保持简短。活动:
public class VideoActivity extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener, EasyPermissions.PermissionCallbacks {
这就是我在 onCreate() 中的内容:
youTubeView.initialize("@string/ytkey", this);
...这就是我对 YoutubePlayer 的看法:
@Override
public void onInitializationSuccess(Provider provider, YouTubePlayer player, boolean wasRestored) {
if (!wasRestored) {
player.loadVideo(userVideo.getYtId());
//player.setFullscreen(true);
}
}
@Override
public void onInitializationFailure(Provider provider, YouTubeInitializationResult errorReason) {
if (errorReason.isUserRecoverableError()) {
errorReason.getErrorDialog(this, RECOVERY_REQUEST).show();
} else {
String error = String.format(getString(R.string.player_error), errorReason.toString());
Toast.makeText(this, error, Toast.LENGTH_LONG).show();
}
}
protected Provider getYouTubePlayerProvider() {
return youTubeView;
}