In this Post I will show you how to Load Interstitial Ad when Navigation Item is clicked.

You can implement this in all your Navigation items or any one Navigation item or even items or odd items.

Watch Below Video for better understanding. 

  • First add Google Play services Library to your gradle dependencies. You can add below line in your dependencies.
compile 'com.google.android.gms:play-services:+'
  • Open your Android Manifest file and add Internet permission to it.
<uses-permission android:name="android.permission.INTERNET" />
  • Now rebuild the project. After rebuilding the project ,
  • Open your Activity file usually MainActivity.java
  • Add below variable to it.
private InterstitialAd interstitial;
  • In onCreate Method of your Acitivity add below lines.
// Prepare the Interstitial Ad
interstitial = new InterstitialAd(MainActivity.this);
  • Now add below lines where ever you want to load the Interstitial Ad. Usually in onNavigation Item Selected.

[ihc-hide-content ihc_mb_type=”show” ihc_mb_who=”reg” ihc_mb_template=”1″ ]

interstitial = new InterstitialAd(getApplicationContext());
interstitial.setAdUnitId(getString(R.string.admob_interstetial_ad));
AdRequest adRequest = new AdRequest.Builder().build();
interstitial.loadAd(adRequest);
interstitial.setAdListener(new AdListener() {
    public void onAdLoaded() {
        if (interstitial.isLoaded()) {
            interstitial.show();
        }
    }
});

[/ihc-hide-content]

  • You need to add above code again wherever you want to load Interstitial ad .
  • Then give your Interstitial ad unit in Strings.xml as below. Admob id below is test ID. Replace the ID with your own Admob Interstetial Ad ID.
<string name="admob_interstetial_ad">ca-app-pub-3940256099942544/1033173712</string>

Install our Android App to get latest Updates.  en_badge_web_generic