How To Insert Both Banner And Interstitial Ads In Android Applications

In my previous post, I have shown you how to insert AdMob Banner Ad and Interstitial Ad in your android app separately. In this post, I will guide you in placing both Banner And Interstitial Ads together. So, let’s get started.

I have assumed that you are using Android Studio for developing your app and your project is opened in it. Follow the below steps and copy-paste the code into your project carefully.

⟩⟩  First of all, you need to add below line of code in your build.gradle dependencies file.

compile ''

after adding the above code you will get sync now option at the top right corner of the page. Click on that and wait for a few minutes to complete the process, once the gradle building is finished you are ready to go with the next steps.

⟩⟩  Now go to activity_main.xml file and paste the following code in your layout.


and in the same file i.e activity_main.xml add below lines of code in the header part


⟩⟩ Then open the Manifest file and add Internet permission to it.

<uses-permission android:name="android.permission.INTERNET" />

⟩⟩  Now open file and add only line number 2 & 3 in public class as shown below in bold.

public class MainActivity extends AppCompatActivity {
InterstitialAd mInterstitialAd;
private InterstitialAd interstitial;

⟩⟩  In the same file i.e add below lines of code in onCreate() method

AdView mAdView = (AdView) findViewById(;
AdRequest adRequest = new AdRequest.Builder().build();

// Prepare the Interstitial Ad
interstitial = new InterstitialAd(MainActivity.this);
// Insert the Ad Unit ID

// Prepare an Interstitial Ad Listener
interstitial.setAdListener(new AdListener() {
     public void onAdLoaded() {
          // Call displayInterstitial() function

⟩⟩  Then add below lines of code before the last curly bracket of 

public void displayInterstitial() {
// If Ads are loaded, show Interstitial else show nothing.
if (interstitial.isLoaded()) {;

⟩⟩  Now open string.xml file in values folder and paste the below line of code.

<string name="banner_ad_unit_id">ca-app-pub-3xxx256099xxxxxx/63009xxxxx</string>
<string name="admob_interstitial_id">ca-app-pub-3xxx25609xxxxxx/10331xxxxx</string>

AdMob ID used here is a sample ID. In order to get revenue, you need to replace this test ID with your own AdMob Ad ID.

If you don’t know how to get your own Ad Id then check the guide on how to get AdMob Ad Unit ID.

Note: Don’t use your real Ad Unit ID while testing and never click on your own Ads it is against AdMob Policy.

That’s it, friends, this is the correct and simple way to insert both the Banner ad and Interstitial Ad in your Application altogether. Just follow the above steps and copy-paste the code carefully at the correct location mentioned above.

If you are a beginner you will love to learn Android Application development from scratch.

Hope you liked this article. If you loved this article please do comment below and share the article to support me. If you have any suggestion please feel free to comment below.

3 thoughts on “How To Insert Both Banner And Interstitial Ads In Android Applications”

  1. Thank you for this. But after following your instructions, I don’t get the test ads to run. I already had Interstitial ads I was trying to add banner ads. Any idea of what I could be missing?

    1. Hello George,

      Banner ca-app-pub-3940256099942544/6300978111
      Interstitial ca-app-pub-3940256099942544/1033173712
      Interstitial Video ca-app-pub-3940256099942544/8691691433
      Rewarded Video ca-app-pub-3940256099942544/5224354917
      Native Advanced ca-app-pub-3940256099942544/2247696110
      Native Advanced Video ca-app-pub-3940256099942544/1044960115

      Here is the test ad unit id you can use them as per the requirement.

Leave a Comment

Your email address will not be published. Required fields are marked *

Sign up for our Newsletter


Award winning hosting company for your website


Best page builder for creating a stunning website


The most popular theme among webmasters