Question

My apps has used the following InterstitialAd, and the below are standard codings obtained from google examples. However, I would like to ask why there is no ad shows? (the app properly show toast: On ReceiveAd)

My main_first_page layout has a ad banner at the bottom too. Will this affect the InterstitialAd?

Thanks!!

public class StartUp extends Activity implements AdListener {

    private InterstitialAd interstitialAd;   
    AdView adView;
    private static final String LOG_TAG = "IQ!";

       public static final  String MY_PUBLISHER_ID = "abc"; 

       @Override
       public void onCreate(Bundle savedInstanceState) 
       {
          super.onCreate(savedInstanceState); // call the superclass's method
          setContentView(R.layout.main_first_page); // inflate the GUI


          Button ButtonNum= (Button) findViewById(R.id.buttonB);
          Button ButtonHeart= (Button) findViewById(R.id.buttonC);
          Button ButtonMath= (Button) findViewById(R.id.buttonD);             

           interstitialAd = new InterstitialAd(this, MY_PUBLISHER_ID); // Create an ad.  
              interstitialAd.setAdListener(this); // Set the AdListener.
              AdRequest adRequest = new AdRequest();
              adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
              interstitialAd.loadAd(adRequest);       

              if (interstitialAd.isReady()) {interstitialAd.show();} 
              else {Log.d(LOG_TAG, "Interstitial ad was not ready to be shown.");}            
       }
/** Called when an ad is clicked and about to return to the application. */
          @Override
          public void onDismissScreen(Ad ad) {
            Log.d(LOG_TAG, "onDismissScreen");
            Toast.makeText(this, "onDismissScreen", Toast.LENGTH_SHORT).show();
          }

/** Called when an ad was not received. */
          @Override
          public void onFailedToReceiveAd(Ad ad, AdRequest.ErrorCode error) {
            String message = "onFailedToReceiveAd (" + error + ")";
            Log.d(LOG_TAG, message);
            Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
          }

/** Called when an ad is clicked and going to start a new Activity that will
           * leave the application (e.g. breaking out to the Browser or Maps
           * application).
           */
          @Override
          public void onLeaveApplication(Ad ad) {
            Log.d(LOG_TAG, "onLeaveApplication");
            Toast.makeText(this, "onLeaveApplication", Toast.LENGTH_SHORT).show();
          }

/* Called when an Activity is created in front of the app (e.g. an
           * interstitial is shown, or an ad is clicked and launches a new Activity).
           */         
        @Override
        public void onPresentScreen(Ad arg0) {
            // TODO Auto-generated method stub          
        }

/** Called when an ad is received. */
        @Override
          public void onReceiveAd(Ad ad) {
            Log.d(LOG_TAG, "onReceiveAd");
            Toast.makeText(this, "onReceiveAd", Toast.LENGTH_SHORT).show();
        }
Was it helpful?

Solution

The interstitial takes time to load. You're checking to see if it's ready directly after loading it, so it definitely won't be ready yet. Check your logcat output, you'll probably see that "Interstitial ad was not ready to be shown." message that you logged.

The interstitial won't be ready until the onReceiveAd() callback is invoked. You can safely place interstitialAd.show() inside the onReceiveAd() callback and the interstitial will show immediately.

Another use case might be you want to show an interstitial at a later time, such as the end of a game level. In which case, you would preload the interstitial at the start of the level, and consult the isReady flag at the end of the level to see if the interstitial is ready yet.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top