3
How to Time an Interstitial Ad?
Example:.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
interstitialAd = new InterstitialAd(Main.this);
interstitialAd.setAdUnitId(getString(R.string.adMobInter));
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice(getString(R.string.adMob_test))
.build();
interstitialAd.loadAd(adRequest);
interstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
displayInterstitial();
}
@Override
public void onAdFailedToLoad(int errorCode) {
onMain();
}
@Override
public void onAdClosed() {
onMain();
}
});
}
public void displayInterstitial() {
if (interstitialAd.isLoaded()) {
interstitialAd.show();
}
}
public void onMain() {
setContentView(R.layout.main); }
What is the programming language? [tag:java] or [tag:c#] for example. Edit in tag if any.
– Florida
Java ( android studio)
– Francis Nascimento
Francis, you don’t need to enter the language in the title, so you have the tags underneath.
– user28595
Thank you @diegofm
– Francis Nascimento