InterstitialAd | Android Developers

Quicknav Quicknav
Links

- Google Play Developer Console
- Android Developers Blog
- About Android

Android Sites

- Android.com
- Android Developers
- Android Open Source Project

Language
close

- - About
  - Wear
  - TV
  - Auto
- - Get Started
  - Devices
  - Style
  - Patterns
  - Building Blocks
  - Downloads
  - Videos
- - Training
  - API Guides
  - Reference
  - Tools
  - Google Services
  - Samples
- - Google Play
  - Essentials
  - Get Users
  - Engage & Retain
  - Monetize
  - Tools & Reference
  - Developer Stories

## Results

Loading...
Summary: Ctors | Methods | Inherited Methods | [Expand All]
public final class

# InterstitialAd

extends Object

java.lang.Object
↳ | com.google.android.gms.ads.InterstitialAd

## Class Overview

Full-screen interstitial ads. The ad unit ID must be set prior to calling `loadAd(AdRequest)`.

Publishers using DoubleClick for Publishers should use `PublisherInterstitialAd`.

Sample code:

     public class MyActivity extends Activity {
         private InterstitialAd mInterstitialAd;
         private Button mNextLevelButton;
         private TextView mTextView;

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

             // Create an interstitial ad. When a natural transition in the app occurs (such as a
             // level ending in a game), show the interstitial. In this simple example, the press of a
             // button is used instead.
             //
             // If the button is clicked before the interstitial is loaded, the user should proceed to
             // the next part of the app (in this case, the next level).
             //
             // If the interstitial is finished loading, the user will view the interstitial before
             // proceeding.
             mInterstitialAd = new InterstitialAd(this);
             mInterstitialAd.setAdUnitId("myAdUnitId");

             // Create an ad request.
             AdRequest.Builder adRequestBuilder = new AdRequest.Builder();

             // Optionally populate the ad request builder.
             adRequestBuilder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);

             // Set an AdListener.
             mInterstitialAd.setAdListener(new AdListener() {
                 @Override
                 public void onAdLoaded() {
                     Toast.makeText(MyActivity.this,
                             "The interstitial is loaded", Toast.LENGTH_SHORT).show();
                 }

                 @Override
                 public void onAdClosed() {
                     // Proceed to the next level.
                     goToNextLevel();
                 }
             });

             // Start loading the ad now so that it is ready by the time the user is ready to go to
             // the next level.
             mInterstitialAd.loadAd(adRequestBuilder.build());

             // Create the button to go to the next level.
             mNextLevelButton = new Button(this);
             mNextLevelButton.setText("Next Level");
             mNextLevelButton.setOnClickListener(new View.OnClickListener() {
                 @Override
                 public void onClick(View view) {
                     // Show the interstitial if it is ready. Otherwise, proceed to the next level
                     // without ever showing it.
                     if (mInterstitialAd.isLoaded()) {
                         mInterstitialAd.show();
                     } else {
                         // Proceed to the next level.
                         goToNextLevel();
                     }
                 }
             });

             // Add the next level button to the layout.
             LinearLayout layout = new LinearLayout(this);
             layout.setOrientation(LinearLayout.VERTICAL);
             layout.addView(mNextLevelButton);

             // Create a TextView to display the current level.
             mTextView = new TextView(this);
             mTextView.setText("Level 1");
             layout.addView(mTextView);

             setContentView(layout);
         }

         public void goToNextLevel() {
             // Show the next level (and disable the next level button since there are no more levels.
             mNextLevelButton.setEnabled(false);
             mTextView.setText("Level 2");
         }
     }

## Summary

Public Constructors
| InterstitialAd(Context context) Construct an `InterstitialAd`.

Public Methods
AdListener | getAdListener() Returns the `AdListener` for this `InterstitialAd`.
String | getAdUnitId() Returns the ad unit ID.
InAppPurchaseListener | getInAppPurchaseListener() Returns the `InAppPurchaseListener` for this `InterstitialAd`.
boolean | isLoaded() Returns `true` if the ad was successfully loaded and is ready to be shown.
void | loadAd(AdRequest adRequest) Start loading the ad on a background thread.
void | setAdListener(AdListener adListener) Sets an `AdListener` for this `InterstitialAd`.
void | setAdUnitId(String adUnitId) Sets the ad unit ID.
void | setInAppPurchaseListener(InAppPurchaseListener inAppPurchaseListener) Set a `InAppPurchaseListener` for this `InterstitialAd`.
void | setPlayStorePurchaseParams(PlayStorePurchaseListener playStorePurchaseListener, String publicKey) Set an `PlayStorePurchaseListener` and app's public key for this `InterstitialAd`.
void | show() Show the interstitial ad.

[Expand] Inherited Methods
From class java.lang.Object
Object | clone()
boolean | equals(Object arg0)
void | finalize()
final Class<?> | getClass()
int | hashCode()
final void | notify()
final void | notifyAll()
String | toString()
final void | wait()
final void | wait(long arg0, int arg1)
final void | wait(long arg0)

## Public Constructors

#### public InterstitialAd (Context context)

Construct an `InterstitialAd`.

## Public Methods

#### public AdListener getAdListener ()

Returns the `AdListener` for this `InterstitialAd`.

#### public String getAdUnitId ()

Returns the ad unit ID.

#### public InAppPurchaseListener getInAppPurchaseListener ()

Returns the `InAppPurchaseListener` for this `InterstitialAd`. Returns `null` if it is not set.

#### public boolean isLoaded ()

Returns `true` if the ad was successfully loaded and is ready to be shown.

#### public void loadAd (AdRequest adRequest)

Start loading the ad on a background thread.

##### Throws

IllegalStateException | If the the ad unit ID has not been set.

#### public void setAdListener (AdListener adListener)

Sets an `AdListener` for this `InterstitialAd`.

#### public void setAdUnitId (String adUnitId)

Sets the ad unit ID.

##### Throws

IllegalStateException | If the ad unit ID was already set.

#### public void setInAppPurchaseListener (InAppPurchaseListener inAppPurchaseListener)

Set a `InAppPurchaseListener` for this `InterstitialAd`. `null` is acceptable but `InAppPurchaseListener` is not set in this case.

##### Throws

IllegalStateException | If `setPlayStorePurchaseParams(PlayStorePurchaseListener, String)` was already called.

#### public void setPlayStorePurchaseParams (PlayStorePurchaseListener playStorePurchaseListener, String publicKey)

Set an `PlayStorePurchaseListener` and app's public key for this `InterstitialAd`. `null` for parameter palyStorePurchaseListener is acceptable but `PlayStorePurchaseListener` is not set in this case. `null` for parameter publicKey is acceptable but SDK will work in developer mode and skip verifying purchase data signature with public key.

##### Throws

IllegalStateException | If `setInAppPurchaseListener(InAppPurchaseListener)` was already called.

#### public void show ()

Show the interstitial ad.