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/interstitialSo 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.