Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AdMob interstitial ad only shown once

Tags:

android

admob

LogCat shows the error message "Tried to launch a new AdActivity with a different ad manager", when the ad should get opend for the second or third time within one session. I am starting the interstitial ad through an intent in the on resume method of my apps main screen:

@Override
public void onResume() {
    super.onResume();

    if(this.getIntent().hasExtra("show_ad")) {
        if(this.getIntent().getExtras().getBoolean("show_ad")) {
            showInterstitialAd();
        }
    }
}

public void showInterstitialAd() {
    mInterstitialAd = new InterstitialAd(this, "ca-app-pub-123456789");
    AdRequest adRequest = new AdRequest();
    mInterstitialAd.loadAd(adRequest);
    mInterstitialAd.setAdListener(this);
}

What can I do to avoid this? What is the meaning of this error message?

like image 436
Herr von Wurst Avatar asked Sep 05 '13 11:09

Herr von Wurst


3 Answers

Are you checking that the first ad is already closed? I had a similar issue, not being able to load admob's interstitial after the first time. I solved it by adding an adListner to the ad

// Set an AdListener.
interstitial.setAdListener(new AdListener() {
    @Override
    public void onAdClosed() {
      AdRequest adRequest = new AdRequest.Builder().addTestDevice(AD_UNIT_ID).build();
      interstitial.loadAd(adRequest);
    }
});
like image 92
idafensp Avatar answered Sep 28 '22 12:09

idafensp


Years passed since last answer, and it's now probably outdated. Official documentation says nothing about "onAdClosed()" (https://developers.google.com/admob/android/interstitial#kotlin)

In my case it works like this, maybe will help someone:

private fun initAdd() {
    MobileAds.initialize(this@MainActivity)
    val adRequest = AdRequest.Builder().build()

    InterstitialAd.load(this,"ca-app-pub-yyyyyyyyyyyyyyyy/xxxxxxxxxx", adRequest, object : InterstitialAdLoadCallback() {
        override fun onAdFailedToLoad(adError: LoadAdError) {
            mInterstitialAd = null
        }

        override fun onAdLoaded(interstitialAd: InterstitialAd) {
            mInterstitialAd = interstitialAd
            mInterstitialAd?.fullScreenContentCallback = object: FullScreenContentCallback() {
                override fun onAdDismissedFullScreenContent() {
                    initAdd()
                    super.onAdDismissedFullScreenContent()
                }
            }
        }
    })
}
like image 35
Andrey Kijonok Avatar answered Sep 28 '22 12:09

Andrey Kijonok


You have to Load Ads each time when you would like to show ads.

add handlers

ex. rewardedAd.OnAdClosed += HandleRewardedAdClosed;

public void HandleRewardedAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
{
   LoadAdRewarded();
}


public void HandleRewardedAdFailedToShow(object sender, AdErrorEventArgs args)
{
   LoadAdRewarded();
}

public void HandleRewardedAdClosed(object sender, EventArgs args)
{
   LoadAdRewarded();
}
like image 33
Владимир Ефанов Avatar answered Sep 28 '22 13:09

Владимир Ефанов