Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;

import java.lang.IllegalStateException;
/**
* Helper class to make interactions between the AdMob C++ wrapper and Java {@link InterstitialAd}
* objects cleaner. It's designed to wrap and adapt a single instance of {@link InterstitialAd},
Expand Down Expand Up @@ -91,15 +92,18 @@ public void initialize(final long callbackDataPtr, Activity activity, String adU
public void run() {
int errorCode;
String errorMessage;
errorCode = ConstantsHelper.CALLBACK_ERROR_ALREADY_INITIALIZED;
errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_ALREADY_INITIALIZED;
if (mInterstitial == null) {
errorCode = ConstantsHelper.CALLBACK_ERROR_NONE;
errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE;
mInterstitial = new InterstitialAd(mActivity);
mInterstitial.setAdUnitId(mAdUnitId);
mInterstitial.setAdListener(new InterstitialAdListener());
} else {
errorCode = ConstantsHelper.CALLBACK_ERROR_ALREADY_INITIALIZED;
errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_ALREADY_INITIALIZED;
try {
mInterstitial = new InterstitialAd(mActivity);
mInterstitial.setAdUnitId(mAdUnitId);
mInterstitial.setAdListener(new InterstitialAdListener());
errorCode = ConstantsHelper.CALLBACK_ERROR_NONE;
errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE;
} catch(IllegalStateException ise) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were you seeing errors while creating a new ad too?
In this block of code, the only thing that can throw this exception is setAdUnitId. Also if that is the case, is the error message representative of the fact?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, it has something to do with using a wrong or changed AdUnitId. But by leaving a possible exception uncaught it ends up crashing JNI instead of failing the future

mInterstitial = null;
}
}

completeInterstitialAdFutureCallback(callbackDataPtr, errorCode, errorMessage);
Expand Down Expand Up @@ -152,7 +156,18 @@ public void run() {
mLoadAdCallbackDataPtr = CPP_NULLPTR;
}
} else {
mInterstitial.loadAd(request);
try {
mInterstitial.loadAd(request);
} catch (IllegalStateException ise) {
synchronized (mInterstitialLock) {
completeInterstitialAdFutureCallback(
mLoadAdCallbackDataPtr,
ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED,
ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED);
mLoadAdCallbackDataPtr = CPP_NULLPTR;
mInterstitial = null;
}
}
}
}
});
Expand Down