I need interstitial ads to reload after 3 clicks, not after every ad close.

retrybutton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        if (mInterstitialAd.isLoaded()) {
            mInterstitialAd.show();
        } else {
            START();
        }
    }
});

mInterstitialAd.setAdListener(new AdListener() {
    @Override
    public void onAdClosed() {
        // Load the next interstitial.
        mInterstitialAd.loadAd(new AdRequest.Builder().build());
    }
});

Every time I click on the Retry button, an ad shows; that's not what I need. I need it to show after 3 clicks.

1 Answers

0
Julio E. Rodríguez Cabañas On Best Solutions

You just need to keep track of the number of clicks and only show a new advert when the count gets up to three:

private int numberOfClicksOnRetryButton = 0;

...

retrybutton.setOnClickListener(new View.OnClickListener() {
    @Override
    public synchronized void onClick(View v) {
        if (mInterstitialAd.isLoaded()) {
            numberOfClicksOnRetryButton++;
            if (numberOfClicksOnRetryButton == 3) {
                // This line is reached if the button has been clicked three times
                mInterstitialAd.show();
                numberOfClicksOnRetryButton = 0;
            }
        } else {
            ...
        }
    }
});