0

After Signing In I start MainActivity and then I added gcm like below:

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);
        }

And then it occurred errors

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)

If I remove gcm code and delete app and install again it will work fine.

I tried to debug on MainActivity but I can't. I don't know what is the root cause and how to figure out the problem.

Luc
  • 2,800
  • 2
  • 25
  • 46

1 Answers1

0

The error message basically means that some component created a binding to a 'service' and did not unbind from the service before the component was destroyed.

The Android runtime destroys an 'IntentService' after onHandleIntent() completes and there are no more Intent requests queued. You can confirm this by adding the 'onDestroy()' method to your IntentService with a log to show when it is called.

If destroy your app with this Service still running then that Service no longer has a purpose. It will exist in memory consuming resources but doing nothing. By unbinding or stopping your Service when you are done, you return these resources so that they can be used by other apps.

Here is a related stack overflow ticket which discuss the activity leaks its service connection.

Community
  • 1
  • 1
Android Enthusiast
  • 4,826
  • 2
  • 15
  • 30