Skip to main content

Splash

1. Load an ad

  • Developers can preload ads before displaying them.

  • Create an advertisement object TPSplash. Some advertisement platforms require an activity to be passed in; otherwise, the advertisement cannot be successfully loaded.

  • You don't need to pass in the container when calling loadAd. You can pass in the container when displaying the ad.

    // Pangle, Yandex, and Google AdMob advertising platforms require an incoming activity
    TPSplash tpSplash = new TPSplash(activity, "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. 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);
    }

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.