Skip to main content

Splash

1. Load an ad

  • Developers can preload ads before displaying them.
  • You don't need to pass in the container when calling loadAd. You can pass in the container when displaying the ad.
  • The same ad slot is a global singleton, meaning only one instance exists.
  • When creating the TPSplash ad object, some domestic ad platforms require an Activity to be passed in (e.g., TapTap, BeiZi, Mintegral-CN, and Vivo). Otherwise, the ad will fail to load.
// Pangle, Yandex, and Google AdMob advertising platforms require an incoming activity
TPSplash tpSplash = new TPSplash(context, "AdUnitID");
tpSplash.setAdListener(new SplashAdListener());
tpSplash.loadAd(null);

2. Show splash ad

  • During a cold start, call loadAd as soon as possible, and display the ad immediately after receiving the onAdLoaded() callback.
  • During a hot start, the advertisement can be loaded in advance. When the app returns to the foreground, call the isReady() method to check whether there is an available advertisement. If an advertisement is available, call the show method to display it.
  • Developers need to provide an ad container(FrameLayout is recommended). Some third parties return it in the form of a view, which can be passed in when loading or displaying. After receiving the onAdClosed() callback, remove the adContainer.
  if (tpSplash.isReady()) {
tpSplash.showAd(adContainer);
}

Pass Activity on Show

  • Supported from V16.8.0.1+
  • An Activity is required when showing AdMob-related ads, Pangle, and Yandex.
if(tpSplash.isReady()) {
tpSplash.showAd(activity,adContainer,adSceneId);
}

3. Register Ad Event Callback

  • Note: Don't retry loading the ad in the onAdFailed() callback – it'll cause a lot of useless requests and could make your app run slowly.
  • After receiving the onAdClosed() callback, remove the adContainer.
  tpSplash.setAdListener(new SplashAdListener() {

@Override
// Callback when the first ad source is loaded successfully; this callback will only be triggered once per load
public void onAdLoaded(TPAdInfo tpAdInfo, TPBaseAd tpBaseAd) {}

@Override
// Callback when the splash ad is clicked
public void onAdClicked(TPAdInfo tpAdInfo) {}

@Override
// Callback when the splash ad appears on the screen
public void onAdImpression(TPAdInfo tpAdInfo) {}

@Override
// Callback when the splash ad fails to load
public void onAdLoadFailed(TPAdError error) {}

@Override
// Callback when the ad display fails (supported by some ad sources)
public void onAdShowFailed(TPAdInfo tpAdInfo, TPAdError error) {}

@Override
// Callback when the splash ad is closed
public void onAdClosed(TPAdInfo tpAdInfo) {
adContainer.removeAllViews();
}
});

4. Code

  • We recommend that you use the SplashActivity to understand the use of the SDK.