title: Android: launching Ads on click of a button
body: <p>I have developed an android application which i have planned to launch it for free on Google Playstore. However, for income purpose, i have embedded AdMob in my app. According to what i have researched, the developer gets paid only on click of the Ads.</p>
  
  <p>What i want to do is, when the user presses the exit button of my app, i would like to launch some Ads/Ad from the AdMob, just before closing my app.</p>
  
  <p>Inorder to achieve this i have the following code:</p>
  
  <pre><code>Button exitButton = findViewById(R.id.exitButton);
  exitButton.setOnClickListener( new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
  
              /*Some code here that would launch an AD*/
  
              MyActivity.this.finish(); //To exit from the app
          }
      }); 
  </code></pre>
  
  <p>The code for displaying an Ad inside an AdView of a layout is:</p>
  
  <pre><code>LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
  AdView adView = new AdView(this, AdSize.BANNER, AdUnitID);
  layout.addView(adView);
  AdRequest adRequest = new AdRequest();
  adRequest.addTestDevice(AdRequest.TEST_EMULATOR); //this is just for testing on emulator
  adView.loadAd(adRequest);
  </code></pre>
  
  <p>Is there a way to launch the contents of the Ads on exit button pressed?</p>
  
  <p>Thanks in advance</p>