Interstitials
1. Load an ad
-
Developers can preload ads before displaying them.
-
To request an interstitial ad, you need to declare a
TPInterstitialobject first, set the listener, and load the ad creative.TPInterstitial tpInterstitial = new TPInterstitial(activity, "AdUnitID");
tpInterstitial.setAdListener(new InterstitialAdListener());
tpInterstitial.loadAd();
2. Show interstitial ad
-
It is recommended to use the
isReady()method to check if ads are ready; if it returns true, you can then display them.if (tpInterstitial.isReady()) {
tpInterstitial.showAd(activity, null);
}
3. Register Ad Event Callback
-
Note: Don't retry loading ads in the
onAdFailedcallback – it'll cause a lot of useless requests and could make your app run slowly.tpInterstitial.setAdListener(new InterstitialAdListener() {
@Override
// Callback when the first ad source is loaded successfully; each load will only trigger the callback once
public void onAdLoaded(TPAdInfo tpAdInfo) {}
@Override
// Interstitial ad clicked
public void onAdClicked(TPAdInfo tpAdInfo) {}
@Override
// Interstitial ad appears on the screen
public void onAdImpression(TPAdInfo tpAdInfo) {}
@Override
// Interstitial ad failed to load
public void onAdFailed(TPAdError error) {}
@Override
// Interstitial ad closed
public void onAdClosed(TPAdInfo tpAdInfo) {}
@Override
// Interstitial ad playback started (supported by some advertising platforms)
public void onAdVideoStart(TPAdInfo tpAdInfo) {}
@Override
// Interstitial ad playback completed (supported by some advertising platforms)
public void onAdVideoEnd(TPAdInfo tpAdInfo) {}
@Override
// Interstitial ad failed to show (supported by some advertising platforms)
public void onAdVideoError(TPAdInfo tpAdInfo, TPAdError error) {}
});
4. Code
- We recommend that you use the InterstitialActivity to understand the use of the SDK.