AdMob:"活动已泄露ServiceConnection"和"AdvertisingIdClient unbindService失败".

 waiwaiwai 发布于 2022-12-09 06:11

我在我的应用中使用AdMob.我遵循了实施指南,横幅正确显示并加载了广告.我的MainActivity负责创建引用,构建AdRequest并显示横幅,以及暂停,恢复和销毁AdView.每次加载AdRequest时,调用Activity的onStop()时,都会创建以下异常:

6706-6706/com.rocca.controlloSpese E/ActivityThread? Activity com.rocca.controlloSpese.MainActivity has leaked ServiceConnection com.google.android.gms.common.b@52b1cc3c that was originally bound here
android.app.ServiceConnectionLeaked: Activity com.rocca.controlloSpese.MainActivity has leaked ServiceConnection com.google.android.gms.common.b@52b1cc3c that was originally bound here
        at android.app.LoadedApk$ServiceDispatcher.(LoadedApk.java:970)
        at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:864)
        at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1577)
        at android.app.ContextImpl.bindService(ContextImpl.java:1560)
        at android.content.ContextWrapper.bindService(ContextWrapper.java:517)
        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.b(SourceFile:239)
        at com.google.android.a.t.f(SourceFile:132)
        at com.google.android.a.t.b(SourceFile:182)
        at com.google.android.a.q.a(SourceFile:258)
        at com.google.android.a.q.a(SourceFile:195)
        at com.google.android.gms.ads.internal.m.a(SourceFile:107)
        at com.google.android.gms.ads.internal.request.c.a(SourceFile:99)
        at com.google.android.gms.ads.internal.util.b.run(SourceFile:17)
        at com.google.android.gms.ads.internal.util.d.call(SourceFile:29)
        at com.google.android.gms.ads.internal.util.e.call(SourceFile:49)
        at java.util.concurrent.FutureTask.run(FutureTask.java:237)
        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)

接下来是这个信息:

6706-6781/com.rocca.controlloSpese I/AdvertisingIdClient? AdvertisingIdClient unbindService failed.
java.lang.IllegalArgumentException: Service not registered: com.google.android.gms.common.b@52b1cc3c
        at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:922)
        at android.app.ContextImpl.unbindService(ContextImpl.java:1611)
        at android.content.ContextWrapper.unbindService(ContextWrapper.java:529)
        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)

如果未构建和加载AdRequest,则不会发生这种情况.我在onCreate()中设置了我的IABHelper,如果用户没有购买我的"移除广告"sku,则会显示广告.这是我用来加载广告的代码:

private void showAds() {
    int adresult = GooglePlayServicesUtil.isGooglePlayServicesAvailable(MainActivity.this);
    if (adresult == ConnectionResult.SUCCESS) {
        //if possible, show ads
        AdRequest adRequest = new AdRequest.Builder()
                .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) 
                .addTestDevice("C144E9DA02EA7B26F74ED2C231F31D38") 
                .addTestDevice("93BABD84466B8C1EF529D2FB39D1ACE8") 
                .addTestDevice("BEAA738068664AE9BBF673E37A782E03") 
                .addTestDevice("E51508081F77DF84C129EE471DE67141") 
                .build();
        adView.setVisibility(View.VISIBLE);
        adView.loadAd(adRequest);
    } else {
        //if there's a problem, show error and close app
        GooglePlayServicesUtil.getErrorDialog(adresult, MainActivity.this, 0, new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialogInterface) {
                finish();
            }
        }).show();
    }
}

adView的pause(),resume()destroy()在相应活动的方法中调用.实际上,应用程序的性能不受影响,但我宁愿避免内存泄漏.我该如何避免这种异常?

编辑:Manifest.xml












    
        
            
            
        
    

    
            

1 个回答
  • 我所看到的正是刚刚从使用AdMob网站的例子快速启动项目相同的行为在这里.我在Nexus5上看到这个正在运行的Lollipop. 因此,这对我来说就像是一个AdMob错误. 无论如何都要获得对AdMob服务的引用并手动取消绑定服务以查看是否会停止错误?
    2022-12-11 01:55 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有