Interstitial Ad – AdListener
loadAd -> onAdLoaded -> show, isLoaded
public class InterstitialActivity extends Activity {
private Button mShowButton;
private InterstitialAd mInterstitial;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_interstitial);
mShowButton = (Button) findViewById(R.id.showButton);
mShowButton.setEnabled(false);
}
public void loadInterstitial(View unusedView){
mShowButton.setEnabled(false);
mShowButton.setText("Loading Interstitial");
mInterstitial = new InterstitialAd(this);
mInterstitial.setAdUnitId("ca-app-pub-xxxx/xxxx");
mInterstitial.astAdListener(new ToastAdListener(this){
@Override
public void onAdLoaded(){
super.onAdLoaded();
mShowButton.setText("Show Interstitial");
mShowButton.setEnabled(true);
}
@Override
public void onAdFailedToLoad(int errorCode){
super.onAdFailedToLoad(errorCode);
mShowButton.setText(getErrorReason());
}
});
AdRequest.on = new AdRequest.Builder().build();
mInterstitial.loadAd(ar);
}
public void showInterstitial(view unusedView){
if (mInterstitial.isLoaded()){
mInterstitial.show();
}
mShowButton.setText("Interstitial Not Ready");
mShowButton.setEnabled(false);
}
}
loadInterstitial
-Create InterstitialAd
-Set AdUnit Id
-Create Listener – onAdLoaded – show, onAdFailedToLoad – error
-Create AdRequest & LiadAd