Step 1

First add below dependency in build.gradle (Module:app)


dependencies {

implementation ‘’

and sync Project

Step 2 

then Open AndroidManifest.xml

go to last of Code and Place below code before last two lines in Manifest , 

last two lines are also given below



android:value=”ca-app-pub-3940256099942544~3347511713″ />



ca-app-pub-3940256099942544~3347511713 is test app id 

You will get your app id when you register your app on admob replace this id with your

app application id

Step 3 

———-    ——–

Admob banner ads tutorial

First go To MainActivity.xml or your desired xml file and place below code in layout












You have to replace 


with your own admob banner ad code

Then go to MainActivity.Java file

After below line Place Main code


AdView adView = findViewById(;

MobileAds.initialize(this , “ca-app-pub-3940256099942544~3347511713”);

AdRequest adRequest = new AdRequest.Builder().build();



you have to replace ca-app-pub-3940256099942544~3347511713

with your application id you get from admob  

Step 4

Admob interstitial ads android tutorial

Place this code in .Java File or MainActivity.Java File

MobileAds.initialize(this , “ca-app-pub-3940256099942544~3347511713”);

final InterstitialAd interstitialAd1 = new InterstitialAd(this);


interstitialAd1.loadAd(new AdRequest.Builder().build());

Button button7 = findViewById(;

button7.setOnClickListener(new View.OnClickListener() {


    public void onClick(View view) {

        if (interstitialAd1.isLoaded()) {


        } else {

            startActivity(new Intent(MainActivity.this, NextActivity.class));




interstitialAd1.setAdListener(new AdListener() {


    public void onAdClosed() {

        interstitialAd1.loadAd(new AdRequest.Builder().build());

        startActivity(new Intent(MainActivity.this, NextActivity.class));




Replace ca-app-pub-3940256099942544~3347511713 in first line with your Application id

Replace ca-app-pub-3940256099942544/1033173712 in third line with your Admob interstitial ad code

Replace button7 in 5 and 6 lines,with your button id on which you want to apply ad

Replace NextActivity.class in 14 and 24 lines with your own activity which should be 

open when user close interstitial ad in lines 2,3,4 ,9,11,19,23 

Don’t place interstitial ad in every activity , Place one interstitial ad after 4-5 activities

If You want to apply interstitial ad on more than one button then

Copy Paste Same Code and Replace interstitialAd1 with interstitialAd2 or some other text of your choice in whole code 

Happy Earning 

Comment Below If you face any problem

Leave a Reply

Your email address will not be published.