ServiceConnection leak error on back button press

3,043 views
Skip to first unread message

Rauno Rüga

unread,
Nov 26, 2014, 4:15:44 PM11/26/14
to google-adm...@googlegroups.com
Hello,

I want to show Interstitial Ad in my app when it launches. I followed AdMob Android guides how to set up manifest.xml and display InterstitialAd. I have also done it perfectly before with my other apps. Now everything worked well, ad was displayed as I wanted it and I was able to navigate inside my app. When I pressed my Android device back button on app main page, app closed as expected on real device, but exception was throw and shown in logcat. I got following exception:

11-26 22:28:24.020  20223-20223/xx.xxxx.xxxxx E/ActivityThread? Activity xx.xxxx.xxxxx.MainActivity has leaked ServiceConnection com.google.android.gms.common.b@42aef5b0 that was originally bound here
    android.app.ServiceConnectionLeaked: Activity xx.xxxx.xxxxx.MainActivity has leaked ServiceConnection com.google.android.gms.common.b@42aef5b0 that was originally bound here
            at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:988)
            at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:882)
            at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1912)
            at android.app.ContextImpl.bindService(ContextImpl.java:1895)
            at android.content.ContextWrapper.bindService(ContextWrapper.java:529)
            at com.google.android.gms.ads.identifier.a.b(SourceFile:330)
            at com.google.android.gms.ads.identifier.a.a(SourceFile:187)
            at com.google.android.gms.ads.identifier.a.a(SourceFile:173)
            at com.google.android.a.u.a(SourceFile:79)
            at com.google.android.a.u.doInBackground(SourceFile:75)
            at android.os.AsyncTask$2.call(AsyncTask.java:288)
            at java.util.concurrent.FutureTask.run(FutureTask.java:237)
            at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
            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)
11-26 22:28:40.926  20223-20270/xx.xxxx.xxxxx I/AdvertisingIdClient? AdvertisingIdClient unbindService failed.
    java.lang.IllegalArgumentException: Service not registered: com.google.android.gms.common.b@42aef5b0
            at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:940)
            at android.app.ContextImpl.unbindService(ContextImpl.java:1946)
            at android.content.ContextWrapper.unbindService(ContextWrapper.java:541)
            at com.google.android.gms.ads.identifier.a.c(SourceFile:275)
            at com.google.android.gms.ads.identifier.b.c(SourceFile:100)
            at com.google.android.gms.ads.identifier.b.run(SourceFile:110)

I was testing it on real device (Samsung S4, Android 4.4.2) and Google play dependency is as follows:
compile 'com.google.android.gms:play-services:6.+'

It must be related to ad, since when I uncomment it, all works fine. On code side, I followed https://developers.google.com/mobile-ads-sdk/docs/admob/android/interstitial
So main logic that calls interstitial looks like:
        interstitial = new InterstitialAd(getActivity());
        interstitial.setAdUnitId(MY_AD_UNIT_ID);

        // Create ad request.
        AdRequest adRequest = new AdRequest.Builder().build();

        // Begin loading your interstitial.
        interstitial.loadAd(adRequest);

        interstitial.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                displayInterstitial();
            }
            @Override
            public void onAdFailedToLoad(int errorCode) {
            }
        });

Any ideas what may have caused such ServiceConnection leak error when closing app by back button press ? I onyl see that error on logcat, in real device there is no drawbacks due to this, but I don't think that just ignoring it will be right solution.

Andrew Brogdon (Mobile Ads SDK Team)

unread,
Nov 26, 2014, 4:38:01 PM11/26/14
to google-adm...@googlegroups.com
Thanks for providing so much detail with your post.  I'm going to pass your information onto our engineers and see if we can narrow down the cause of the service leak.  

I should warn you that tomorrow starts a holiday weekend here in the States, so you will probably not hear back from me until early next week.  I'll get back to you as soon as I know more, though.

One last question: Does the phone on which you're testing have the latest version of Google Play Services?

-Andrew

Rauno Rüga

unread,
Nov 26, 2014, 4:47:33 PM11/26/14
to google-adm...@googlegroups.com
Thank you for quick response. I am not that hurry with it.

About my phone: Yes, I think it has latest version of Google Play Service. I have autoupdates turned on and  I just checked, I have no new updates. App info shows Google Play services as version 6.5.87

Rauno

Miquel Martín

unread,
Dec 3, 2014, 7:06:21 PM12/3/14
to google-adm...@googlegroups.com
Same issue here:

12-04 01:01:43.709: E/ActivityThread(29511): Activity com.appfeel.precioenergia.CordovaApp has leaked ServiceConnection com.google.android.gms.common.b@42809510 that was originally bound here
12-04 01:01:43.709: E/ActivityThread(29511): android.app.ServiceConnectionLeaked: Activity com.appfeel.precioenergia.CordovaApp has leaked ServiceConnection com.google.android.gms.common.b@42809510 that was originally bound here
12-04 01:01:43.709: E/ActivityThread(29511): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:979)
12-04 01:01:43.709: E/ActivityThread(29511): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:873)
12-04 01:01:43.709: E/ActivityThread(29511): at android.app.ContextImpl.bindServiceAsUser(ContextImpl.java:1833)
12-04 01:01:43.709: E/ActivityThread(29511): at android.app.ContextImpl.bindService(ContextImpl.java:1821)
12-04 01:01:43.709: E/ActivityThread(29511): at android.content.ContextWrapper.bindService(ContextWrapper.java:503)
12-04 01:01:43.709: E/ActivityThread(29511): at com.google.android.gms.ads.identifier.a.b(SourceFile:330)
12-04 01:01:43.709: E/ActivityThread(29511): at com.google.android.gms.ads.identifier.a.a(SourceFile:187)
12-04 01:01:43.709: E/ActivityThread(29511): at com.google.android.gms.ads.identifier.a.b(SourceFile:239)
12-04 01:01:43.709: E/ActivityThread(29511): at com.google.android.a.t.f(SourceFile:132)
12-04 01:01:43.709: E/ActivityThread(29511): at com.google.android.a.t.b(SourceFile:182)
12-04 01:01:43.709: E/ActivityThread(29511): at com.google.android.a.q.a(SourceFile:258)
12-04 01:01:43.709: E/ActivityThread(29511): at com.google.android.a.q.a(SourceFile:195)
12-04 01:01:43.709: E/ActivityThread(29511): at com.google.android.gms.ads.internal.m.a(SourceFile:107)
12-04 01:01:43.709: E/ActivityThread(29511): at com.google.android.gms.ads.internal.request.c.a(SourceFile:99)
12-04 01:01:43.709: E/ActivityThread(29511): at com.google.android.gms.ads.internal.util.b.run(SourceFile:17)
12-04 01:01:43.709: E/ActivityThread(29511): at com.google.android.gms.ads.internal.util.d.call(SourceFile:29)
12-04 01:01:43.709: E/ActivityThread(29511): at com.google.android.gms.ads.internal.util.e.call(SourceFile:49)
12-04 01:01:43.709: E/ActivityThread(29511): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
12-04 01:01:43.709: E/ActivityThread(29511): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
12-04 01:01:43.709: E/ActivityThread(29511): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
12-04 01:01:43.709: E/ActivityThread(29511): at java.lang.Thread.run(Thread.java:841)

Miquel Martín

unread,
Dec 3, 2014, 7:08:05 PM12/3/14
to google-adm...@googlegroups.com
Using Google Play Services 6171000

Andrew Brogdon (Mobile Ads SDK Team)

unread,
Dec 3, 2014, 8:06:05 PM12/3/14
to google-adm...@googlegroups.com
Thanks for the additional info.  I'll add your stack trace and version number to the bug report.

-Andrew

Adam J

unread,
Dec 9, 2014, 3:44:47 PM12/9/14
to google-adm...@googlegroups.com
There bug has been reported by many developers on many forums. This is causing serious memory leak.
When will this be fixed by admob? This must be priority one, I guess.

Andrew Brogdon (Mobile Ads SDK Team)

unread,
Dec 10, 2014, 1:39:39 PM12/10/14
to google-adm...@googlegroups.com
We don't give timetables for individual fixes, but our engineers are working on the issue.

-Andrew

Matthew Bridgeman

unread,
Dec 12, 2014, 6:43:48 AM12/12/14
to google-adm...@googlegroups.com
Same issue as well. Figure this might be useful for you:

12-12 11:40:09.036: E/ActivityThread(16131): Activity com.synthdark.casesimulatorfree.android.AndroidLauncher has leaked ServiceConnection com.google.android.gms.common.b@422083a8 that was originally bound here
12-12 11:40:09.036: E/ActivityThread(16131): android.app.ServiceConnectionLeaked: Activity com.synthdark.casesimulatorfree.android.AndroidLauncher has leaked ServiceConnection com.google.android.gms.common.b@422083a8 that was originally bound here
12-12 11:40:09.036: E/ActivityThread(16131): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:1078)
12-12 11:40:09.036: E/ActivityThread(16131): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:972)
12-12 11:40:09.036: E/ActivityThread(16131): at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1809)
12-12 11:40:09.036: E/ActivityThread(16131): at android.app.ContextImpl.bindService(ContextImpl.java:1792)
12-12 11:40:09.036: E/ActivityThread(16131): at android.content.ContextWrapper.bindService(ContextWrapper.java:524)
12-12 11:40:09.036: E/ActivityThread(16131): at com.google.android.gms.ads.identifier.a.b(SourceFile:330)
12-12 11:40:09.036: E/ActivityThread(16131): at com.google.android.gms.ads.identifier.a.a(SourceFile:187)
12-12 11:40:09.036: E/ActivityThread(16131): at com.google.android.gms.ads.identifier.a.a(SourceFile:173)
12-12 11:40:09.036: E/ActivityThread(16131): at com.google.android.a.u.a(SourceFile:79)
12-12 11:40:09.036: E/ActivityThread(16131): at com.google.android.a.u.doInBackground(SourceFile:75)
12-12 11:40:09.036: E/ActivityThread(16131): at android.os.AsyncTask$2.call(AsyncTask.java:288)
12-12 11:40:09.036: E/ActivityThread(16131): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
12-12 11:40:09.036: E/ActivityThread(16131): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
12-12 11:40:09.036: E/ActivityThread(16131): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
12-12 11:40:09.036: E/ActivityThread(16131): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
12-12 11:40:09.036: E/ActivityThread(16131): at java.lang.Thread.run(Thread.java:864)

Andrew Brogdon (Mobile Ads SDK Team)

unread,
Dec 12, 2014, 12:19:59 PM12/12/14
to google-adm...@googlegroups.com
Thanks.  I'll pass that along.

-Andrew

Sushant Patil

unread,
Dec 13, 2014, 1:08:05 PM12/13/14
to google-adm...@googlegroups.com
Hello,

This exception occurs due to you use same Ad unit Id - Create different Id and try.

If you use same Id for different package it will not work. Use Different Id for Different package;

Chris

unread,
Dec 14, 2014, 10:07:59 AM12/14/14
to google-adm...@googlegroups.com
In my case it has to do with banner refresh
After some time refresh fails and admob crash with code_internal_error. After that Abmob will not work on that device on any app. It will work again after device restart.
When admob does not work I get ServiceConnectiion leak.

charly baquero

unread,
Dec 15, 2014, 4:37:58 PM12/15/14
to google-adm...@googlegroups.com
Hi, running the example's code to display a banner gives the following error log:

12-15 15:48:13.899  21350-21350/com.google.android.gms.example.bannerexample E/ActivityThread﹕ Activity com.google.android.gms.example.bannerexample.MyActivity has leaked ServiceConnection com.google.android.gms.common.b@27a481f9 that was originally bound here
    android.app.ServiceConnectionLeaked: Activity com.google.android.gms.example.bannerexample.MyActivity has leaked ServiceConnection com.google.android.gms.common.b@27a481f9 that was originally bound here
            at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:1072)
            at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:966)
            at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1768)
            at android.app.ContextImpl.bindService(ContextImpl.java:1751)
            at android.content.ContextWrapper.bindService(ContextWrapper.java:538)
            at com.google.android.gms.ads.identifier.a.b(SourceFile:330)
            at com.google.android.gms.ads.identifier.a.a(SourceFile:187)
            at com.google.android.gms.ads.identifier.a.a(SourceFile:173)
            at com.google.android.a.u.a(SourceFile:79)
            at com.google.android.a.u.doInBackground(SourceFile:75)
            at android.os.AsyncTask$2.call(AsyncTask.java:288)
            at java.util.concurrent.FutureTask.run(FutureTask.java:237)
            at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
            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:818)

STEPS TO REPRODUCE:
1. Run the sample
2. Rotate the device

SDK tools version: 24.0.1
Android Studio version: 1.0.1
Android Support Library revision 21.0.3
Google Play Services revision 22

Tested on
Model number: Nexus 5
Android version: 5.0
Build number: LRX21O

Link to the example code:
https://developers.google.com/mobile-ads-sdk/docs/admob/android/quick-start#complete_code_example

Thanks!

Bence Hegedüs

unread,
Dec 17, 2014, 3:59:15 AM12/17/14
to google-adm...@googlegroups.com
I have the exact same problem as the OP.

Could you tell me please if it is a bug or if we can avoid this exception somhow?
Thanks
Bence

Andrew Brogdon (Mobile Ads SDK Team)

unread,
Dec 17, 2014, 12:16:24 PM12/17/14
to google-adm...@googlegroups.com, hegeb...@gmail.com
This appears to be a bug, and we don't currently have a workaround.  That said, the engineers are working on correcting it, and we'll let everyone know when a fix is ready for release.

Thanks!

-Andrew

Gavriel Fleischer

unread,
Jan 18, 2015, 2:21:16 PM1/18/15
to google-adm...@googlegroups.com
Any fixes since last month?

You might be interested in a workaround (not tested by me) described here in Joe's answer:
http://stackoverflow.com/questions/26525185/what-is-causing-google-admob-to-leak-serviceconnection



Andrew Brogdon (Mobile Ads SDK Team)

unread,
Jan 20, 2015, 1:50:46 PM1/20/15
to google-adm...@googlegroups.com
We're currently in the process of verifying that our fix is doing the job.  If you're still seeing this issue in devices running the latest version of Google Play services and apps that are built with the latest version of the Google Repository / Play services library, please let me know.

-Andrew

Gavriel Fleischer

unread,
Jan 21, 2015, 3:06:18 AM1/21/15
to google-adm...@googlegroups.com
Yes indeed, that's why I was asking for the fix. At least in the emulator: API 21, Android Support Repository: 11, 'com.google.android.gms:play-services-ads:6.5.87'
Reply all
Reply to author
Forward
0 new messages