Android Interstitial Ads

Interstitial is a full screen ad that appears between levels, before or after viewing content. To add interstitial ad, you have to perform the steps below:

  1. Implement ADFListener

public class MainActivity extends Activity implements ADFListener{
	.
	.
		public void onLoadAd(ADFAd ad) {
		}

		public void onError(ADFAd ad, ADFErrorCode code, String message) {
		}

		public void onPresentAdScreen(ADFAd ad) {
		}

		public void onDismissAdScreen(ADFAd ad) {
		}

		public void onLeaveApplication() {
		}
	}

  1. Create instance of ADFInterstitial and load new interstitial ad.
protected void onCreate(Bundle savedInstanceState) {
		.
		.
		ADFInterstitial adfInterstitial = new ADFInterstitial(this, "your site ID",	this);
		adfInterstitial.loadInterstitialAd();
		.
		.
	}
  1. When the interstitial is loaded successfully and becomes ready to display the Ad, the SDK will fire onLoadAd method. Therefore, you will need to implement onLoadAd interface’s method as below:
	public void onLoadAd(ADFAd ad) {
		if(ad instanceof ADFInterstitial){
			((ADFInterstitial)ad).showInterstitialAd();
		}
	}

  1. To know if any error has occurred during the loading including “no available ad”. You will need to implement onError interface’s method as the below
	public void onError(ADFAd ad, ADFErrorCode code, String message) {
		if(ad instanceof ADFInterstitial){
			if(code == ADFErrorCode.NO_AD_AVAILABLE){
				//Do anything here
			}else if(code == ADFErrorCode.COMMUNICATION_ERROR){
				//Do anything here
			}else if(code == ADFErrorCode.MISSING_PARAM){
				//Do anything here
			}else{
				//Do anything here
			}
		}
	}

To learn more about Errors codes go to: ADFErrorCode