Dash Stats Docs

Interstitial

Showing the interstitial

../_images/interstitial.png

The AppBrain interstitial is the main way to generate revenue with the AppBrain SDK. The interstitial asks users if they are interested in seeing the AppBrain offerwall, which promotes free apps to your users. Each app a user installs from the offerwall will generate revenue for you.

The best moment to show the interstitial is at a natural pause moment in your app, for instance when an important event just has completed, such as sending a photo or finishing a game level, or when leaving the app.

The easiest way to create an interstitial is using the InterstitialBuilder class. We recommend creating the InterstitialBuilder in your activity’s onCreate(), so it can start loading in the background. Then, for example in a view’s OnClickListener, you can show the interstitial using InterstitialBuilder.show().

Instead of calling show() you can also call maybeShow(). When using that method, the AppBrain SDK automatically makes sure the interstitial is only shown occasionally, which is why maybe is in the method name. Therefore it’s safe to call this method in multiple places without having to do your own rate limiting.

In-app interstitial

If you want a specific action to happen after a user closes the interstitial, you can use an InterstitialListener. Here is an example of how to show the interstitial in a game at the end of a level, and start the next level when the user closes the interstitial:

private InterstitialBuilder interstitialBuilder;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    interstitialBuilder = InterstitialBuilder.create().setAdId(AdId.LEVEL_COMPLETE)
        .setListener(new InterstitialListener() {
            @Override
            public void onAdLoaded() {}

            @Override
            public void onAdFailedToLoad(InterstitialError error) {}

            @Override
            public void onPresented() {}

            @Override
            public void onClick() {}

            @Override
            public void onDismissed(boolean wasClicked) {
                // Preload again, so we can use interstitialBuilder again.
                interstitialBuilder.preload(getContext());
                loadNextLevel();
            }
        }).preload(getContext());
}

public void onLevelCompleted() {
    if (!interstitialBuilder.maybeShow(getContext()) {
        // When the interstitial doesn't show, the InterstitialListener won't be called,
        // so we need to go to the next level here.
        loadNextLevel();
    }
}

To get a more detailed look at this example, see In-depth look at interstitials.

Interstitial on app exit

To show the interstitial when the user leaves your Activity, first create an InterstitialBuilder in onCreate():

private InterstitialBuilder interstitialBuilder;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    interstitialBuilder = InterstitialBuilder.create().setAdId(AdId.EXIT)
        .setFinishOnExit(this).preload(this);
}

Then, you can show the interstitial when the back button is pressed:

@Override
public void onBackPressed() {
    if (!interstitialBuilder.show(this)) {
        super.onBackPressed();
    }
}

Note however, that if your activity puts fragments on the FragmentManager back stack, you should make sure the back stack is empty before showing the interstitial:

@Override
public void onBackPressed() {
    if (getFragmentManager().getBackStackEntryCount() > 0
        || !interstitialBuilder.show(this)) {
        super.onBackPressed();
    }
}

This examples and more options are discussed in detail on the In-depth look at interstitials page.