终结器引发的未捕获的异常:所有WebView方法必须在同一线程上调用。 (预期的Looper) [英] Uncaught exception thrown by finalizer: All WebView methods must be called on the same thread. (Expected Looper )

查看:389
本文介绍了终结器引发的未捕获的异常:所有WebView方法必须在同一线程上调用。 (预期的Looper)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Admob sdk 18.1.1

I am using Admob sdk 18.1.1

并收到错误终结器抛出未捕获的异常

and getting error Uncaught exception thrown by finalizer

java.lang.RuntimeException: java.lang.Throwable: A WebView method was called on thread 'FinalizerDaemon'. All WebView methods must be called on the same thread. (Expected Looper Looper (main, tid 2) {f4f671a} called on null, FYI main Looper is Looper (main, tid 2) {f4f671a})

此问题是否发生在admob sdk内部?

Is this issue occurred inside the admob sdk ?

堆栈跟踪:

at android.webkit.WebView.checkThread(WebView.java:2732)
        at android.webkit.WebView.evaluateJavascript(WebView.java:1128)
        at com.google.android.gms.internal.ads.zzbbq.evaluateJavascript(com.google.android.gms:play-services-ads@@18.1.1:108)
        at com.google.android.gms.internal.ads.zzbbq.zza(com.google.android.gms:play-services-ads@@18.1.1:144)
        at com.google.android.gms.internal.ads.zzbbq.zzfk(com.google.android.gms:play-services-ads@@18.1.1:151)
        at com.google.android.gms.internal.ads.zzbbq.zza(com.google.android.gms:play-services-ads@@18.1.1:190)
        at com.google.android.gms.internal.ads.zzbbq.zza(com.google.android.gms:play-services-ads@@18.1.1:101)
        at com.google.android.gms.internal.ads.zzbbq.zzav(com.google.android.gms:play-services-ads@@18.1.1:630)
        at com.google.android.gms.internal.ads.zzbbq.onDetachedFromWindow(com.google.android.gms:play-services-ads@@18.1.1:434)
        at android.view.View.dispatchDetachedFromWindow(View.java:18583)
        at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3793)
        at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3785)
        at android.view.ViewGroup.removeViewInternal(ViewGroup.java:5375)
        at android.view.ViewGroup.removeViewInternal(ViewGroup.java:5346)
        at android.view.ViewGroup.removeView(ViewGroup.java:5277)
        at com.google.android.gms.ads.internal.overlay.zze.onDestroy(com.google.android.gms:play-services-ads@@18.1.1:125)
        at com.google.android.gms.internal.ads.zzbbq.destroy(com.google.android.gms:play-services-ads@@18.1.1:472)
        at com.google.android.gms.internal.ads.zzbbo.destroy(com.google.android.gms:play-services-ads@@18.1.1:106)
        at com.google.android.gms.internal.ads.zzbrc.finalize(com.google.android.gms:play-services-ads@@18.1.1:33)
        at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:256)
        at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:243)
        at java.lang.Daemons$Daemon.run(Daemons.java:109)
        at java.lang.Thread.run(Thread.java:764)
     Caused by: java.lang.Throwable: A WebView method was called on thread 'FinalizerDaemon'. All WebView methods must be called on the same thread. (Expected Looper Looper (main, tid 2) {f4f671a} called on null, FYI main Looper is Looper (main, tid 2) {f4f671a})

操作系统:Android 7.1,8.0,8.1,9.0正在获得相同的错误日志

OS: Android 7.1 , 8.0 , 8.1 , 9.0 are getting same error logs

推荐答案

此问题主要是由于您使用的是插页式广告。因为我遇到了同样的问题,并且Google拒绝了我为该应用所做的任何更新,直到我修复了该问题。

this issue is mostly caused because you're using interstitial ads. because i had the same issue and google refused any update i made for the app until i "fixed" the issue.

此处的问题是,插页式广告会尝试

the problem here, is that interstitial ads will try to load also when you exit the app tapping on the home button.

所以您必须在退出应用程序时也加载广告。

so you have to block the ads from loading when you leave the app.

您可以尝试执行此操作(我所做的事情):

you can try this (what i have done):

在活动/片段中创建一个字段变量,例如
private boolean shouldLoadAds ;

in your activiy/fragment create a field variable, like private boolean shouldLoadAds;

在onCreate()中,您可以初始化插页式广告:

in your onCreate() you initialise your Interstitial:

mInterstitialAd = new InterstitialAd(this);
mInterstitialAd .setAdUnitId(getString(R.string.adview_interstitial));
mInterstitialAd .loadAd(new AdRequest.Builder().build());

,当您调用插页式广告来显示它时,您可以这样做:

and when you call the interstitial to show it, you do it like this:

if(mInterstitialAd != null && mInterstitialAd .isLoaded()) {
            mInterstitialAd .show();
            mInterstitialAd .setAdListener(new AdListener(){
                @Override
                public void onAdClosed() {
                    super.onAdClosed();
                    if(shouldLoadAds) { //load the ad only if shouldLoadAds == true
                        mInterstitialAd .loadAd(new AdRequest.Builder().build());
                    }
                    //here some code, what should be done, after the ads is cloded
                }
            });
        }

然后您必须覆盖 onStart()并在 onStop()上像这样:

then you have to override onStart() and on onStop() like this:

@Override
    public void onStart() {
        super.onStart();
        shouldLoadAds= true;
    }

    @Override
    public void onStop() {
        shouldLoadAds= false;
        super.onStop();
    }

这篇关于终结器引发的未捕获的异常:所有WebView方法必须在同一线程上调用。 (预期的Looper)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆