title: How to ensure to show exit ad in android?
body: <p>In my android app I'm using <a href="http://www.mopub.com/" rel="nofollow">MoPub</a> to show an interstitial on app exit. It is working fine, except when user quickly presses back button twice, app exits without showing any interstitial. I want to ensure that interstitial is shown if it's available.</p>
  
  <p>Here's the relevant code</p>
  
  <pre><code>// InterstitialAdListener methods
      @Override
      public void onInterstitialLoaded(MoPubInterstitial interstitial) {
          // This sample automatically shows the ad as soon as it's loaded, but
          // you can move this show call to a time more appropriate for your app.
          // if (interstitial.isReady()) {
          //    mMoPubInterstitial.show();
          // }
          // We're doing nothing here, we'll load the ad when exit
      }
  
      @Override
      public void onInterstitialFailed(MoPubInterstitial interstitial, MoPubErrorCode errorCode) {
          Log.d("MoPub", "Interstitial load failed: " + errorCode);
      }
  
      @Override
      public void onInterstitialShown(MoPubInterstitial interstitial) {
      }
  
      @Override
      public void onInterstitialClicked(MoPubInterstitial interstitial) {
      }
  
      @Override
      public void onInterstitialDismissed(MoPubInterstitial interstitial) {
          finish(); //this will exit the program if interstitial is closed
      }
  </code></pre>
  
  <p>And here's my onBackPressed method where I'm showing the ad</p>
  
  <pre><code>@Override
      public void onBackPressed() {
              if (mInterstitial.isReady()) {
                  mInterstitial.show(); //this will show the interstitial if it's ready
              } else {
                  super.onBackPressed(); //this will exit the program
              }
      }
  </code></pre>