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?
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);
}
});
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()
}
}
}
})
}
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With