How to Add AdMob Interstitial Ads in Your Android Apps

On September 13, 2012, in Android, Make Money Online, by James Liu

Sometimes, the Banner Ads are too small to monetize your apps maximally. One reason is that Banner Ads are too small. Because of this, the click rate is quit low even the fill rate are near 100%. Banner Ads size are limited in 4 types:

Admob Banner Ads Size
Size Device
320 x 50 Phones and Tablets
300 x 250 Tablets
468 x 60 Tablets
728 x 90 Tablets

To increase the click through rate, there is an alternative ads type to choose. Interstitials, rich HTML 5 experiences ads, can present a full screen ads immediately on your phone and tablet screen. Without the size limitations, the interstitial ads make them more expensive and subjects to impression constraints. The bigger ads size is, the more expensive it is, the higher click through rate and you earn more from your apps. The following example will show you how to add interstitial ads in your android apps.

Interstitial Ads is a full screen type. We don’t need to add any view in layout files. In this interstitial ads example, I will put one text view and one button on the top of the screen. When user click the load interstitial button, the example app will send the ad request to the adMob server. When the ads is returned and get ready to show, interstitial ads will be popup on the screen with a small close button on the top left. Here is the main layout example code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
    android:orientation="vertical" >

        android:text="@string/hello" />
    <Button android:id="@+id/loadButton"

Now, let’s the main activity source code in this example. In the activity class, I set an onClick listener on the button and set the activity class as the adListener. When user click the button, it will generate an AdRequest, add my device to test device and load the adMob interstitial advertisement. Here is the code snapshot:

	public void onCreate(Bundle savedInstanceState) {

		this.interstitialAds = new InterstitialAd(this, "a150272e162142c");

		Button loadButton = (Button) this.findViewById(;

		this.textView = (TextView) this.findViewById(;

	private OnClickListener loadButtonOnClick = new OnClickListener() {

		public void onClick(View v) {
			// TODO Auto-generated method stub
			textView.setText("Loading Intertitial Ads");

			AdRequest adr = new AdRequest();
			// add your test device here

Because the activity class is the adListener, we have to implement several asListener functions. I just introduce you two important method here. The first method is onReceiveAd(). In this method (function), we check if the interstitial ads is ready to show. If it is, we show the ads. Otherwise, we show the text message in textView. The second method is onFailedToReceiveAd(). This is a error handler. Once the ads failed to show, this method will be invoked. In our example, we will show the error message in textView. Now, let’s see the source code about these two methods.

	public void onReceiveAd(Ad arg0) {
		if (interstitialAds.isReady()) {;
		} else {
			textView.setText("Interstitial ad was not ready to be shown.");

	public void onFailedToReceiveAd(Ad ad, ErrorCode error) {
		String message = "Load Ads Failed: (" + error + ")";

In the stage, all necessary code are done. Let’s run the app and see the result. The following snapshot is the example result. Because I add my Samsung android tablet in test device list, AdMob returns the test ad to my device.

adMob interstitial ads example

adMob interstitial ads example screen

onFailedToReceiveAd error solution

Many developers mentioned that they always receive onFailedToReceivedAd error. The error log message is like this:

onFailedToReceiveAd(Ad request successful, but no ad returned due to lack of ad inventory.)

As the message described, this is because AdMob lacks interstitial ads to show. This is quite common when there is no ads to show. It doesn’t mean your code is incorrect. In this case, you can either to show one picture instead, or request other ads from different mobile ad providers.

Download and try AdMob Intersitital Ads Example App

Interstital Ads Example Source Code

Download Example Source Code

Tagged with:  

16 Responses to “How to Add AdMob Interstitial Ads in Your Android Apps”

  1. rank says:

    Hi Great Tutorials

    I have few question .
    1. when i use your code, I got only NDTV image on emulator.
    2. But again ,when i use own publisher id it will also give same response with same image.
    3. Market://details?id= and http:// ,why we use these all, at time of generating publisher id
    what is difference between them..

    Can you tell me, where i am wrong.
    Please also send me reply on my mail

    Thanks in Advance.

    • James says:

      As Admob official comments, market://details?id= is recommended to use for linking your App which is in Android Market. And http:// is for apps that are not in Android Market. If you want to ask why they need this info to create AdMob, I guess admob team want to trace the publish id usage. I think AdMob Team also want us to use a unique for a unique apps. Therefore, they want to know which app will use the ads publish id.


  2. gadis says:

    Where I find this code “adr.addTestDevice(“8E452640BC83C672B070CDCA8AB9B06B”) ? especially 8E452640BC83C672B070CDCA8AB9B06B, is it code admob or anything ?

    • James says:

      For setting test mode on device, make an AdRequest on device, and check LogCat. The SDK will says something like:

      To get test ads on this device, call adRequest.addTestDevice(“0123456789ABCDEF0123456789ABCDEF”);

      This number is a hash of your device ID, and it’s easiest to get from LogCat.

  3. gadis says:

    James, you use LinearLayout but I have RelativeLayout, how to adding admob interstitial to RelativeLayout ? Please help me with example home layout code, thanks

    • James says:

      Why do you want to put the interstitial ad to RelativeLayout? The admob sdk will handle the layout of interstitial ad view. It will be put on the screen automatically. Did you read my code? I didn’t handle the layout of interstitial ad view.


  4. cris says:

    i used the code , it work good but the question : what is the logic time between two click of the button , i am warry that admob ban me if the user click more clicks.
    for example if the time is 3 seconds , is this logic and acceptable by admob ??

    • James says:


      I think you don’t need to worry about it. Admob already handle this issue in their system.

  5. Elvis Jorge says:

    Hi guys,

    I’m having problem creating the ads in a non-activity class. I developed a game, this run two threads to draw and manage the events in the game, I couldn’t create the ads because I need to create it in a non-activity class, could you help me with it, please I need to see an example.

    Thanks and best regards

    • James says:

      When you want to create an AdView, you need context reference. Hence, you can create AdView or ads in any class as long as you can pass a context reference.

      Best Regards

  6. faical says:

    where i can get AD_INTERSTITIAL_UNIT_ID ?

  7. ryan says:

    how do i get the example APP above to work on my phone?

  8. Umesh Sarkar says:

    in single apk, can i use two different admob ad_id ?
    i mean, I have an app, in that app banner ad and interstellar ad is there so could I put ad banner with ad unitid of admob account A and Interstellar ad unitid of admob account b in single apk?

Leave a Reply

WordPress Blog

Premium WordPress Themes