interstitialad on click android
private InterstitialAd mInterstitialAd; // Initialize
// on create
MobileAds.initialize(this, getResources()
.getString(R.string.App_ID));
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
mInterstitialAd.loadAd(new AdRequest.Builder().build());
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
//call this method to refresh ad
mInterstitialAd.loadAd(new AdRequest.Builder().build());
Intent intent = new Intent(yourActivity.this, NextActivity.class);
startActivity(intent);
}
});
Button button = findViewById(R.id.button);
button.setOnClickListener(v -> {
if (mInterstitialAd != null) {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
/////inApp Counter
} else {
Intent intent = new Intent(yourActivity.this, NextActivity.class);
startActivity(intent);
}
}
});