com.google.ads
Class InterstitialAd

java.lang.Object
  extended by com.google.ads.InterstitialAd
All Implemented Interfaces:
Ad

public class InterstitialAd
extends Object
implements Ad

A class for full-screen interstitial ads. Sample code:

   public class MyActivity extends Activity implements AdListener {
     private InterstitialAd interstitialAd;

     public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);

       // Create an ad.
       interstitialAd = new InterstitialAd(this, "adUnitId");

       // Create an ad request.
       AdRequest adRequest = new AdRequest();
       // Fill out ad request.

       // Register an AdListener.
       ad.setAdListener(this);

       // Start loading the ad in the background.
       interstitialAd.loadAd(adRequest);
     }

     public void onDestroy() {
       // Stop loading the ad.
       interstitialAd.stopLoading();

       super.onDestroy();
     }

     public void onReceiveAd(Ad ad) {
       // Be sure to check that it is an InterstitialAd that triggered this
       // callback. Also, if there are multiple InterstitialAds, make sure it
       // is the correct one.
       if (ad == interstitialAd) {
         // For best performance, make sure you are not performing
         // processor-intensive or media-intensive operations while showing
         // interstitial ads.
         interstitialAd.show();
       }
     }
   }
 
Another option is to simply call show() (which checks isReady()) when the interstitial should be shown. If it hasn't loaded by this point, nothing will show.


Constructor Summary
InterstitialAd(Activity activity, String adUnitId)
          Creates an InterstitialAd with a long load timeout.
InterstitialAd(Activity activity, String adUnitId, boolean shortTimeout)
          Creates an InterstitialAd.
 
Method Summary
 boolean isReady()
          See Ad.isReady().
 void loadAd(AdRequest adRequest)
          Download an ad using the supplied AdRequest.
 void setAdListener(AdListener adListener)
          Set an AdListener for this InterstitialAd.
 void show()
          Show the interstitial ad if it's loaded and ready to show.
 void stopLoading()
          Stops loading the ad.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InterstitialAd

public InterstitialAd(Activity activity,
                      String adUnitId)
Creates an InterstitialAd with a long load timeout.

Parameters:
activity - the associated Activity.
adUnitId - the ad unit ID.

InterstitialAd

public InterstitialAd(Activity activity,
                      String adUnitId,
                      boolean shortTimeout)
Creates an InterstitialAd. Use shortTimeout to indicate if the interstitial should have a short load timeout, making it suitable for use immediately when an app opens.

Parameters:
activity - the associated Activity.
adUnitId - the ad unit ID.
shortTimeout - a flag to indicate that the interstitial should have a short load timeout value.
Method Detail

isReady

public boolean isReady()
See Ad.isReady().

Specified by:
isReady in interface Ad
Returns:
true if the ad is successfully loaded and is ready to be shown.
See Also:
Ad.isReady()

loadAd

public void loadAd(AdRequest adRequest)
Download an ad using the supplied AdRequest.

Specified by:
loadAd in interface Ad
Parameters:
adRequest - the AdRequest used to fetch the ad.

show

public void show()
Show the interstitial ad if it's loaded and ready to show. Otherwise does nothing.


setAdListener

public void setAdListener(AdListener adListener)
Set an AdListener for this InterstitialAd.

Specified by:
setAdListener in interface Ad
Parameters:
adListener - the AdListener.

stopLoading

public void stopLoading()
Stops loading the ad.

Specified by:
stopLoading in interface Ad