Uncaught exception thrown by finalizer: All WebVie

2019-08-17 10:51发布

问题:

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

Is this issue occurred inside the admob sdk ?

Stack trace:

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

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

回答1:

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):

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

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

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


标签: android admob