public class InterstitialAd

  1. Object
  2. InterstitialAd

A full screen interstitial ad shown at natural break points such as between game levels or activities.

InterstitialAd ad = new InterstitialAd("ca-app-pub-xxx/yyy");
ad.setAdListener(new AdListener() {
    public void onDismissed() { ad.load(); } // preload the next one
});
ad.load();

// later, at a natural break such as the end of a level
if (ad.isLoaded()) {
    ad.show();
}

Show the ad at the break you chose rather than from onLoaded(). Because onDismissed() loads the next ad, a show() inside onLoaded() makes each dismissal open another ad and the user cannot get out of the sequence.

All callbacks are delivered on the EDT. You can also let Codename One show an interstitial automatically on screen transitions with AdManager.bindInterstitialOnTransition(InterstitialAd, int).

Constructors

public InterstitialAd(String adUnitId)Creates an interstitial for the given ad unit id.

Methods

public void setAdListener(AdListener listener)Sets the listener notified of this ad’s lifecycle events.
public AdListener getAdListener()The listener notified of this ad’s lifecycle events, may be null.
public void load()Loads an ad with default targeting.
public void load(AdRequest request)Loads an ad using the supplied targeting metadata.
public boolean isLoaded()True when an ad is loaded and ready to show().
public void show()Presents the loaded ad.
public void dispose()Releases the resources held by this ad.

Inherited methods

Constructor details

InterstitialAd

public InterstitialAd(String adUnitId)
Creates an interstitial for the given ad unit id.

Parameters

adUnitId String
the ad unit identifier from the network console

Method details

setAdListener

public void setAdListener(AdListener listener)
Sets the listener notified of this ad’s lifecycle events.

getAdListener

public AdListener getAdListener()
The listener notified of this ad’s lifecycle events, may be null.

load

public void load()
Loads an ad with default targeting.

load

public void load(AdRequest request)
Loads an ad using the supplied targeting metadata.

Parameters

request AdRequest
optional targeting metadata, may be null

isLoaded

public boolean isLoaded()
True when an ad is loaded and ready to show().

show

public void show()
Presents the loaded ad. Does nothing if no ad is loaded.

dispose

public void dispose()
Releases the resources held by this ad.