Admob is a great way for earning money from the app. Admob is a multi-platform mobile network which allows you to integrate ads in your app and monetize the app. There are two types of Ad unit one is Banner and the second one is Interstitial

Banner Ad occupies only some portion of device screen but Interstitial Ad occupies full screen of the device.

In this article, we build a simple app for showing Banner AdMob in your android app.

Follow these steps for integrating AdMob in an android application:

1) Create Ad Units

1.1:  Go to and login to your AdMob account. If you are new then signup.

1.2:  Click on Monetize tab and create the app and also choose the platform ( like Android or ios).

1.3:  Select Ad type i.e Banner or Interstitial and give the ad unit name.

1.4:  After creation of ad unit you can see ad unit id on the dashboard.

2) Create Project:

2.1: Create new Android project (eg. AdMob)


2.2: Select Target SDK Version


2.3: Now select Empty Activity


2.4: now click on Finish button and project is setup


2.5: Project Structure


2.6: Now Open build.Gradle file and add the dependency for Admob

compile ‘’ 

File: Build.gradle


dependencies {
   compile fileTree(dir: 'libs', include: ['*.jar'])
   androidTestCompile('', {
       exclude group: '', module: 'support-annotations'
   compile ''
   testCompile 'junit:junit:4.12'
   compile ''

2.7: Now Add ad unit ID’s in your strings.xml file

File: res/values/strings.xml

<string name="banner_home_footer">ca-app-pub-0664570763252260/3326522424</string>
<string name="interstitial_full_screen">ca-app-pub-0664570763252260/1769900428</string>

2.8: Open AndroidManifest.xml and add the permissions for internet and network state.

File: Manifest.xml

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

3) Now UI part:

3.1:  Add ad view in main activity XML.

File: res/layout/activity_main.xml










4) Now Java Part

4.1: Create an instance of AdRequest and load the ad into AdView.

4.2: Add the AdView life cycle methods in onResume(), onPause() and in onDestroy() methods.

File: src/



import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

   private AdView adView;

   protected void onCreate(Bundle savedInstanceState) {

       adView = (AdView) findViewById(;
       AdRequest adRequest = new AdRequest.Builder()

   public void onPause() {
       if (adView != null) {

   public void onResume() {
       if (adView != null) {

   public void onDestroy() {
       if (adView != null) {

5) Almost Done! Now run the app and you see a banner ad at bottom of screen


Happy Coding :)

Download the Demo Example → Download Demo