Interstitial Ads are full screen ads that pop up in a mobile app and have a dismiss button that allows the user to dismiss the ad and resume interaction with the app or continue to its destination. The best times to show interstitial ads are at pauses in game play or times when there is a natural break in an app’s flow.
Before integrating interstitial ads in your app, you’ll need to go through the steps in our Getting Started Guide to integrate the SDK into your project.
Interstitial ads do not appear in layouts. They are created exclusively in code.
To request interstitial ads, create an object of YaftaMobileInterstitial
that handles fetching and displaying interstitial ads, pass the current activity that owns this instance, and an implementation of InterstitialAdListener
, this is the listener interface you have to implement to get notified when an interstitial ad loaded, failed to load or was dismissed. Once the interstitial ad is loaded, the InterstitialAdListener.OnAdLoaded()
event will be invocked where the ad can be safely displayed
Here’s a code snippet that shows how to load an interstitial ad.
public class MainActivity extends Activity implements InterstitialAdListener{
....
YaftaMobileInterstitial intersitialAd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
/* Create the YaftaMobileInterstital, pass activity and interstitialAdListener */
intersitialAd=new YaftaMobileInterstitial(this, this);
/* Request an inerstitial ad to be fetched*/
intersitialAd.requestAd(new AdRequest());
}
.....
}
Add the following InterstitialActivity declaration within the <application...>
tag:
<activity
android:name="com.mustamara.yaftamobile.sdk.ads.interstitial.InterstitialActivity"
android:configChanges="keyboard|keyboardHidden|orientation" />
Use the following to display as soon as it is ready
@Override
public void OnAdLoaded() {
Toast.makeText(getApplicationContext(), "Ad successfully loaded.",
Toast.LENGTH_SHORT).show();
/* Display the loaded interstitial ad */
intersitialAd.showAd();
}