【问题标题】:Activity com.facebook.FacebookActivity has leaked ServiceConnection com.google.android.gms.common.zza that was originally bound hereActivity com.facebook.FacebookActivity 泄露了原本绑定在这里的ServiceConnection com.google.android.gms.common.zza
【发布时间】:2016-03-18 00:04:20
【问题描述】:

Signing In 之后我开始MainActivity 然后我添加了gcm,如下所示:

mRegistrationBroadcastReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                SharedPreferences sharedPreferences =
                        PreferenceManager.getDefaultSharedPreferences(context);
                boolean sentToken = sharedPreferences
                        .getBoolean(Constants.SENT_TOKEN_TO_SERVER, false);
                if (sentToken) {
                    Log.d(TAG, "Token retrieved and sent to server!");
                } else {
                    Log.d(TAG, "An error occurred while either fetching the InstanceID token,\n" +
                            "        sending the fetched token to the server or subscribing to the PubSub topic. Please try\n" +
                            "        running the sample again.");
                }
            }
        };

        registerReceiver();
        if (checkPlayServices()) {
            // Start IntentService to register this application with GCM.
            Intent intent = new Intent(this, RegistrationIntentService.class);
            startService(intent);
        }

然后出现错误

03-18 06:51:38.279 19336-19336/com.domain.example E/ActivityThread: Activity com.facebook.FacebookActivity has leaked ServiceConnection com.google.android.gms.common.zza@4210c6a0 that was originally bound here
                                                                  android.app.ServiceConnectionLeaked: Activity com.facebook.FacebookActivity has leaked ServiceConnection com.google.android.gms.common.zza@4210c6a0 that was originally bound here
                                                                      at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:970)
                                                                      at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:864)
                                                                      at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1786)
                                                                      at android.app.ContextImpl.bindService(ContextImpl.java:1769)
                                                                      at android.content.ContextWrapper.bindService(ContextWrapper.java:536)
                                                                      at com.google.android.gms.common.stats.zzb.zza(Unknown Source)
                                                                      at com.google.android.gms.common.stats.zzb.zza(Unknown Source)
                                                                      at com.google.android.gms.ads.identifier.AdvertisingIdClient.zzp(Unknown Source)
                                                                      at com.google.android.gms.ads.identifier.AdvertisingIdClient.zzb(Unknown Source)
                                                                      at com.google.android.gms.ads.identifier.AdvertisingIdClient.getAdvertisingIdInfo(Unknown Source)
                                                                      at java.lang.reflect.Method.invokeNative(Native Method)
                                                                      at java.lang.reflect.Method.invoke(Method.java:515)
                                                                      at com.facebook.internal.Utility.invokeMethodQuietly(Utility.java:1019)
                                                                      at com.facebook.internal.AttributionIdentifiers.getAndroidId(AttributionIdentifiers.java:93)
                                                                      at com.facebook.internal.AttributionIdentifiers.getAttributionIdentifiers(AttributionIdentifiers.java:125)
                                                                      at com.facebook.appevents.AppEventsLogger.getSessionEventsState(AppEventsLogger.java:795)
                                                                      at com.facebook.appevents.AppEventsLogger.access$600(AppEventsLogger.java:147)
                                                                      at com.facebook.appevents.AppEventsLogger$5.run(AppEventsLogger.java:749)
                                                                      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
                                                                      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
                                                                      at java.lang.Thread.run(Thread.java:841)
03-18 06:51:38.299 19336-19336/com.domain.example E/ActivityThread: Activity com.facebook.FacebookActivity has leaked ServiceConnection com.google.android.gms.common.zza@4210df10 that was originally bound here
                                                                  android.app.ServiceConnectionLeaked: Activity com.facebook.FacebookActivity has leaked ServiceConnection com.google.android.gms.common.zza@4210df10 that was originally bound here
                                                                      at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:970)
                                                                      at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:864)
                                                                      at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1786)
                                                                      at android.app.ContextImpl.bindService(ContextImpl.java:1769)
                                                                      at android.content.ContextWrapper.bindService(ContextWrapper.java:536)
                                                                      at com.google.android.gms.common.stats.zzb.zza(Unknown Source)
                                                                      at com.google.android.gms.common.stats.zzb.zza(Unknown Source)
                                                                      at com.google.android.gms.ads.identifier.AdvertisingIdClient.zzp(Unknown Source)
                                                                      at com.google.android.gms.ads.identifier.AdvertisingIdClient.zzb(Unknown Source)
                                                                      at com.google.android.gms.ads.identifier.AdvertisingIdClient.getAdvertisingIdInfo(Unknown Source)
                                                                      at java.lang.reflect.Method.invokeNative(Native Method)
                                                                      at java.lang.reflect.Method.invoke(Method.java:515)
                                                                      at com.facebook.internal.Utility.invokeMethodQuietly(Utility.java:1019)
                                                                      at com.facebook.internal.AttributionIdentifiers.getAndroidId(AttributionIdentifiers.java:93)
                                                                      at com.facebook.internal.AttributionIdentifiers.getAttributionIdentifiers(AttributionIdentifiers.java:125)
                                                                      at com.facebook.appevents.AppEventsLogger.getSessionEventsState(AppEventsLogger.java:795)
                                                                      at com.facebook.appevents.AppEventsLogger.access$600(AppEventsLogger.java:147)
                                                                      at com.facebook.appevents.AppEventsLogger$5.run(AppEventsLogger.java:749)
                                                                      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
                                                                      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
                                                                      at java.lang.Thread.run(Thread.java:841)

如果我删除 gcm 代码并删除应用程序并再次安装它会正常工作。

我尝试在MainActivity 上进行调试,但我不能。我不知道根本原因是什么以及如何找出问题所在。

【问题讨论】:

  • 您是否仍然遇到此问题?

标签: android google-cloud-messaging facebook-sdk-4.0


【解决方案1】:

错误消息基本上意味着某些组件创建了与'service' 的绑定,并且在组件被销毁之前没有与服务解除绑定。

Android 运行时在 onHandleIntent() 完成后销毁 'IntentService' 并且没有更多 Intent 请求排队。您可以通过将“onDestroy()”方法添加到您的 IntentService 来确认这一点,并在日志中显示它何时被调用。

如果在此服务仍在运行的情况下销毁您的应用,则该服务不再具有用途。它将存在于内存中消耗资源但什么都不做。通过在完成后解除绑定或停止服务,您可以返回这些资源,以便其他应用可以使用它们。

这是一个相关的stack overflow ticket,它讨论了活动泄漏其服务连接。

【讨论】:

    猜你喜欢
    • 2013-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-31
    • 1970-01-01
    • 2015-11-14
    • 2013-11-24
    相关资源
    最近更新 更多