Interstitial ads - adiant/android-sdk-example GitHub Wiki
Add the AdActivity to your AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.app" >
<!-- ... -->
<activity android:name="com.adiant.android.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />
<!-- ... -->
</manifest>
In your activity, instantiate the InterstitialAd class, and give it your ad unit ID. Load an ad in the background, and show the add when the user proceeds forward in your app.
private InterstitialAd interstitial;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// create interstial ad
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId("13323-2709803565");
interstitial.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
doTheNextThing();
}
});
// load our first ad in the background
interstitial.loadAd();
// button listener to show ad
final Button nextButton = (Button) findViewById(R.id.buttonNext);
nextButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (interstitial.isLoaded()) {
interstitial.show();
} else {
// handle case where as has not loaded
doTheNextThing();
}
}
});
// rest of your code ...
}
Add a hook to clean-up resources in the the activity's onDestroy() method.
@Override
protected void onDestroy() {
if (interstitial != null) {
interstitial.destroy();
}
super.onDestroy();
}