Integrating New Google Admob with Banner and Interstitial ads

  • mina kumari

    unfortunately app has stopped

    • AndroidBegin

      Hi, I’ve just tested it again on API 4.3 , its running fine. Did you generate your own Device Test ID to test it out first? Show me some logcat errors please. Thanks.

      • mina kumari

        thanks now work

        but only display in emulator when i publish app and install device not load ads only open blank page

        • AndroidBegin

          If it works in your emulator, it should work on your device too. Please double check your Test Device ID.

  • ibrahim

    Thx very much

  • J Ahsan

    Hi got an error.Please help …java.lang.NoClassDefFoundError:

    • AndroidBegin

      Hi, did you import the Google Play Services Library into your project?

      • J Ahsan

        I have added the as a android code—> marked it as a library–>went to my project properties to reference it–> cleaned both project –RUn (ERROR)

        • Deepak Kanyan

          plz check you import

        • TechnoRapper dotcom

          same problem with me

          • Mohamed Ahmed

            is the problem still existing ?

          • Mohamed Ahmed

            is the problem still exist ?

          • TechnoRapper dotcom

            no now its working

        • Mohamed Ahmed

          is the problem still exist ?

  • bluesky214

    You should have version for latest android studio,much easier to use when importing sdk,libraries and jar files

    • AndroidBegin

      Agreed with Bluesky.

  • Me

    Also getting java.lang.NoClassDefFoundError:…I have tried for hours to figure out why, but no answer.

  • Amit Kumar Khare

    Working Like a charm. Thanks a lot. :)

  • Alex

    I do not understand why an error: “The constructor InterstitialAd(FileCategoryActivity) is undefined”?

  • sameer

    my app was removed by google play saying that Interstitial ads may only be displayed inside of the app they came with. So how to achieve this?

  • Sanjay

    Can any one help me in integrating admob with a sample Hello world. Please help me on adding new admob with the app.

    • Mohamed Ahmed

      have you solved the problem ?

  • william aristizabal

    properties android reference error google play service eclipse

  • Sinchan Maitri

    ” Exception raised during rendering: com/google/android/gms/ads/AdView : Unsupported major.minor version 51.0

    Exception details are logged in Window > Show View > Error Log ”

    i am getting this for all the apps. Please suggest me what to do….

  • TC Ibrahim YENER

    Excellent tutorial. Easy to understand and easy to follow.
    Thanks for it.
    Keep up good work.

  • Nelson Osorio

    Thank you!! Great Tutorialt!!

  • alex

    1 error to create apk
    Dex Loader] Unable to execute dex: Multiple dex files define Lcom/google/ads/AdRequest$ErrorCode;

    Because this error ?

    • cherryapp

      remove old jar

  • Neil

    I can not get this going for love or money . has anyone got a working demo please
    I am using eclipse juno and can not get the hang of adding admob
    All I get is errors .

  • itechaleart

    Yaa, it’s working and superb demo, its really so easy for understating.

  • Paweł Lewiński

    Hello, great tutorial which worked for me. I have a question what changes can I make to have the small banner only, without interstitial? Thanks in advane.

    • Vamsi Challa

      Use code only related to Banner Ads from the above example

  • asdssa

    I really love you Thank you very much really really Thank you

  • Govind Bhanushali

    I followed the same steps and did all as step by step, but i can not see any ads in banner. and for interstitial, it never showing ads. Please suggest where i am doing wrong, the code is completly the same as above. i can see the sessions and all in adMob site report too. but banner is not coming with any ads. it simply grey blank banner

    • sd vipeen

      Did u switch on internet connection in ur mob.?
      bcas even i had the same prob..

  • Vivek Gandhi

    Does AdMob work properly in JellyBean? I was able to load Ads in IceCream Sanwich and Kitkat, but not in jellybean. Someone please advice me

  • Onwuasoanya Ndubuisi George

    Worked perfectly. This is fantastic.

  • pakistantutor

    It did not work for me.
    I see some unknown errros in MainActivity
    Android Manifest and others

    • AndroidBegin

      Hi, could you please paste your errors on for us to have a look at your issue? Thanks :)

  • suresh

    Thanx buddy. It really helped.

  • Junico Rudyanto

    how about its?
    + no error
    + google-play-services_lib ” Done ”
    + using eclipse juno..
    – undetect google play service in library

    i have to follow your code about .xml, .java, & android manifest but but the ad has still not shown

    • Guest

      Right click on Google plays services lib project -> android.
      Click on “as library” then try to readded it to your project.

      • Junico Rudyanto

        resolved thanks :)

    • Lê Mạnh Huy

      Right click on Google plays services lib project -> properties -> android.
      Click on “as library” then try to readded it to your project.

  • Łukasz Żymła

    Hi, great tutorial, many thanks, but i have a questions.
    My app must be in play store to have a statistic? Beacuse I add my own add id and it’s show with Your code, but in admob account i don’h have any stats.

    • Łukasz Żymła

      sorry, now i have stats, they show after 24h

  • LoKey

    Hi, I am tying to incorporate this in my Java fragment extended class.. The code below: interstitial = new InterstitialAd(HomeFragment.this);
    is giving me this error message:
    The constructor InterstitialAd(HomeFragment) is undefined……

    Do you know why?

    • MattyDeBie

      try interstitial = new InterstitalAd( getActivity() );

  • manideep

    I have tried the same example by replacing interstitial.setAdUnitId(“ca-app-pub-123456789/123456789”); with my id , it was throwing null pointer exception at adView.loadAd(;

  • Ajay Kumar

    Hi., can i add my account details in admob., or is it any problem., bca admob asking my CVV and expiry date also.,pls help me

    • Alexander Nowak

      It’s your credit card information

  • John Hillen

    Hello, I tried your example and getting any Warnings and a Error code 0 after loading the ad. I use the latest google service api revision 22. I have set the Ad Unit ID for interstitial in the MainActivity and the Ad Unit ID in the main_activity.xml and copied the number for the test device from LogCat. But for all times no Ads are loaded.

    Additional I tried the google play service from your example, but with the same error.

    Tested on:
    Nexus4 – Android 5.0.1

  • Vamsi Challa

    Easy and precise as it should be.. Nice!!!

  • Terrence Markle

    Hello All… This was a very good tutorial. However, I am having a problem. I have copied the, activity_main.xml, and AndroidManifest.xml (minSdk=9 and targetSdk=19) directly into the Eclipse project “NewAdmobTutorial” as presented in this tutorial and checked all the code. When I run the project (Run -> Run As -> Android Application), I get the error “Android library projects cannot be launched”. I Google searched for a solution but nothing worked. I used the Android SDK Manager to install Google Play Services (Rev. 22) and imported the “google-play-services.jar” into the Eclipse project as an Android Private Libraries.The “is Library” box is checked in the project’s Property -> Android -> Library. I checked the Java Build Path and (1) in the Order and Export section the Android Private Libraries box is checked and (2) in the Libraries section the google-play-services.jar is included in the Android Dependencies and Android Private Libraries. I do not know what to try next. I hope someone can provide a solution for me.

    • AndroidBegin

      Hi Terrence, I understand your frustration. Before you try this tutorial, you have to know how to import libraries and configure your project properties. Copy and paste might work sometimes. I suggest you start with some of our less complicated tutorials. :)

      • Terrence Markle

        Hi AndroidBegin,… Thank you for your response. Yes, I am frustrated. I’ve been trying to get the Admob feature working for about a week.
        1. I followed all of Google’s docs for installing the Google Play Services Library using the Android SDK Manager in Eclipse IDE.
        2. I setup your project (Integrating New Google Admob…) by manually typing each line of code into Eclipse (no errors encountered).
        3. I imported the google-play-services.jar (as an Android Private Library) into the project.
        4. I checked the Java Build Path and it looks OK.
        5. When I ticked (check marked) the “is Library” box in the Property/Android/Library and tried to run the project, I got the error “Android library project cannot be launched”.
        6. When I removed the tick mark in “is Library” and tried to run the project, Eclipse displayed “Process system isn’t responding”.
        7. Question #1: Should the “is Library” box be ticked or not ticked?
        8. Question #2: Where do I find the tutorial that you mentioned that will help me solve this problem? I appreciate any help you can give me.
        Best regards,

        • Wajid Ali

          dear Sir I have same problem.. but can’t find Solution…. when I run the Project then error show :(

  • Wajid Ali

    any body can post the complete project of Admob…?

  • William Ferguson

    Please stop telling people to call from onAdLoaded(). It will get their Admob accounts banned.

    • AndroidBegin

      Hi William Ferguson, could you please elaborate more on your comment? or maybe some references? Thank you

      • William Ferguson

        Admob has always said that interstitial ads should be shown at a natural break point in your app. Showing them when the ad has finished loading means that you have no control over when they will be shown. Typically it will be 10-40 seconds after you called load() which means that the user gets interrupted in the middle on their task – perhaps the game they are playing. It is *very* poor UX and Admob regularly bans accounts for exactly this practice. I’m speaking with some good understanding of the issue as I am a Google Developer Expert for Admob.

        • AndroidBegin

          Thank you for your time and its my pleasure to welcome you to my blog. I will make sure this valuable comment being noted by all developers that visited this tutorial. Thanks and regards.


          Hello willian , i see u have experience on google ads, can u please write me on email an teach how to add interstitital ads on start and exit of my android app, i’m new and step by step guide will be very helpful to me ::D

          email:[email protected]

          • William Ferguson

            An ad on exit will be extremely difficult to pull off, and an ad on start will not be the best user experience because it takes takes for the ad to load. You are better off finding a natural break point in your app. If your app doesn’t have one, then I would suggest that interstitials are not a good option for your app.

          • DanielVAVAVAVAVAVAVAVA

            i want interstitial add to show 3 sec after user enters on my appliccation, becuse its not a game and i dont have or something like that, if you help me to implement my interstitial ad on my project i will be very thankfull 😀 step by step guide, i saw the examples in google develope but its not what i search for:D than you

          • Yuvaraj Rajamanickam Coimbator

            soon i will teach you.

        • Joey

          What’s the recommended frequency for interstitials? I have a studying app for a major exam in my country where the user spends about 3-7 minutes on a page. My natural break point will be when they’re going to the next page because it’s usually a totally different topic, but what would you consider spamming and what would you consider good UX? I’m currently jobless, I don’t want to be greedy and drive away customers, but I could also use some $$$. Every 5 minutes? 10, 20?

          • William Ferguson

            Put yourself in the mind of your users and start with a value that seems reasonable. Your users will let you know if you’ve got it wrong :-). For break points around the 5 minute mark I like to randomly show an ad about 20-25% of the time. That way they are getting one interstitial on average every 20-25 mins and the pattern is non-determinstic.

    • Chrislley Alves
      • William Ferguson

        @chrislleyalves:disqus what’s your point?

        • Chrislley Alves

          At the documentation AdMob says you have to char .show () so that the announcement can be displayed. If not call .show (), the announcement will not appear.

          • William Ferguson

            That is correct, but don’t call it from onAdLoaded.

          • Chrislley Alves


    • Ananth S

      thanks dude…this means a lot

  • Vikas Dhiman

    One suggestion, better to use Android Studio for your future tutorials.


      shut the fuck up. I m using libgdx on eclipse and this works for me

  • anusha pavan kumar

    this code is not working
    i tried many times
    another code is working
    but in android 5.01 which code is working
    can any one tell pls

  • Ananth S

    both banner ad and interstitial ads explained simply on same page…thank you !

  • Suman Yadav

    Thank you for this code….

  • Vignesh Raja

    I tried the code , but interstitial ad works fine , but banner ads is not loading at all , it shows blank space in the banner ads area

  • RK BT

    can i use 2 ads evry ads from an account admob it mean 2 account adbmob in the same app

  • Orange

    Thanks :)

  • Mohamed Dhanish
  • Nino

    For preventing real ads showing in my own device, is it okay to keep addTestDevice in the code even for publication to google play store? Do others that playing my game will still display the real ads?

    Thankyou :)

  • Nishant Meena

    how can i use my own ad on my own app