public class InterstitialAd extends Object implements Ad
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. interstitialAd.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 and Description |
---|
InterstitialAd(Activity activity,
String adUnitId)
Creates an InterstitialAd with a long load timeout.
|
InterstitialAd(Activity activity,
String adUnitId,
boolean shortTimeout)
Creates an InterstitialAd.
|
Modifier and Type | Method and Description |
---|---|
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.
|
public InterstitialAd(Activity activity, String adUnitId)
activity
- the associated Activity
.adUnitId
- the ad unit ID.public InterstitialAd(Activity activity, String adUnitId, boolean shortTimeout)
shortTimeout
to indicate if the
interstitial should have a short load timeout, making it suitable for use
immediately when an app opens.activity
- the associated Activity
.adUnitId
- the ad unit ID.shortTimeout
- a flag to indicate that the interstitial should have a
short load timeout value.public boolean isReady()
Ad.isReady()
.isReady
in interface Ad
true
if the ad is successfully loaded and is ready to be
shown.Ad.isReady()
public void show()
public void setAdListener(AdListener adListener)
AdListener
for this InterstitialAd
.setAdListener
in interface Ad
adListener
- the AdListener
.public void stopLoading()
stopLoading
in interface Ad