3

I'm showing interstitial ad in my app and ads are loading and displaying perfectly but the issue is that ads are not closing when I click cross button on back button I have to quit my app to close them I created a new project and checked the ads in new project they are working fine and closing on back button but in my main app ads are not closing once they displayed to user this is my Admob class

public class Admob {

    public static InterstitialAd mInterstitial; // Interstital
    private static AdView mAdView; // banner

    public static void createLoadInterstitial(final Context context, View view)

    {

        mInterstitial = new InterstitialAd(context);
        mInterstitial.setAdUnitId(context.getResources().getString(
                R.string.admob_showIntersitial_ad_unit_id));
        mInterstitial.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                // TODO Auto-generated method stub
                showInterstitial();
            }

            @Override
            public void onAdFailedToLoad(int errorCode) {
                // TODO Auto-generated method stub

                super.onAdFailedToLoad(errorCode);
            }

            @Override
            public void onAdOpened() {
                // TODO Auto-generated method stub
                super.onAdOpened();

            }

            @Override
            public void onAdClosed() {
                // TODO Auto-generated method stub
                super.onAdClosed();

            }

            @Override
            public void onAdLeftApplication() {
                // TODO Auto-generated method stub
                // Called when an ad leaves the app (for example, to go to the
                // browser).

                super.onAdLeftApplication();
            }

        });

        loadInterstitial();

    }

    public static void loadInterstitial() {

        mInterstitial.loadAd(new AdRequest.Builder().
                addTestDevice("").//ca-app-pub-3940256099942544/1033173712
                build());
    }

    public static void showInterstitial() {
        if (mInterstitial.isLoaded()) {
            mInterstitial.show();
        }
    }

    public static void createLoadBanner(final Context context, View view) {
        mAdView = (AdView) view.findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().
                addTestDevice("").//ca-app-pub-3940256099942544/6300978111
                build();
        mAdView.loadAd(adRequest);

        mAdView.setAdListener(new AdListener() {

            @Override
            public void onAdLoaded() {
                // TODO Auto-generated method stub


                super.onAdLoaded();
            }

            @Override
            public void onAdClosed() {
                // TODO Auto-generated method stub

                super.onAdClosed();

            }

            @Override
            public void onAdOpened() {
                // TODO Auto-generated method stub

                super.onAdOpened();
            }

            @Override
            public void onAdLeftApplication() {
                // TODO Auto-generated method stub


                super.onAdLeftApplication();
            }

            @Override
            public void onAdFailedToLoad(int errorCode) {
                // TODO Auto-generated method stub


                super.onAdFailedToLoad(errorCode);
            }

        });

    }

}

This is how I show them in my activity

 MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713");

        Admob.createLoadInterstitial(this,null);

I have initialize this in Mainfest also

  <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-3940256099942544~3347511713" />

I saw same questions on stackoverflow but none of them is answered the solution so any help will be really appreciated

Umair Solis
  • 78
  • 1
  • 5
  • Did you resolve the issue? I am also facing the same problem. – Nakshtra Pradhan Mar 15 '21 at 12:59
  • nope still getting the same issue didn't get the solution but when I tried the same code in new app it was working fine ,now don't know was it due to my code or its a bug from admob side – Umair Solis Mar 16 '21 at 08:31
  • same case with me. I tried the same admob implementation in another app and its working fine. It seems to me, that some dependencies are causing this chaos, but not 100% sure. – Nakshtra Pradhan Mar 16 '21 at 19:17
  • I had the same issue and I solved it by removing the pausing of webviews I had in other parts of my code. – gxcare Dec 02 '21 at 00:04

1 Answers1

1

If you are using Webiew check if there is webview is paused on ad shown

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/32322937) – The Dreams Wind Jul 29 '22 at 11:09