Facebook Ads Error : You can't call show() for ad in state LOADING
You are using the wrong dependency. Replace the following dependency:
implementation 'com.facebook.android:audience-network-sdk:5.+'
with
implementation 'com.facebook.android:audience-network-sdk:5.0.1'
Hi: you need to check if your ad is not null and if it is loaded before show it:
if(fbInterstitialAd != null && fbInterstitialAd.isAdLoaded()) fbInterstitialAd.show();
I updated the facebook ads from 5.0.1 to 5.3.1 and I have the same error:
java.lang.IllegalStateException: You can't call load() for ad in state LOADING. Previous states: LOADING << CREATED. You can change Integration Error mode by setting AdSettings.setIntegrationErrorMode()
This error happened when you trying to load a new ad when the previous is loading. What did they smoke when writing code? They should redirect the error to "onError" method, but they decide to throw an IllegalStateException
My solution is not elegant, but it is working:
// load the ad
public void load() {
if (interstitialAd != null) {
try {
interstitialAd.loadAd();
} catch (Throwable e) {
// Do nothing, just skip and wait for ad loading
}
}
}
// show the ad
public void show() {
if (interstitialAd != null && interstitialAd.isAdLoaded()) {
try {
interstitialAd.show();
} catch (Throwable e) {
// Do nothing, just skip and wait for ad loading
}
}
}