7

I recently added an interstitial ad using Admob with the Google Play services library (which is still pretty buggy BTW).

The interstitial is working well but the following call:

// Begin loading interstitial
interstitial.loadAd(adInterstitialRequest);

is very slow, it can delay up to 2 seconds the first launch of my app.

What could I do to avoid this? I followed exactly the example provided by Google here.

FYI I tried to load the ad in the background using an AsyncTask but it does not seem possible to do it:

03-23 15:50:21.939: E/AndroidRuntime(3572): Caused by: java.lang.IllegalStateException: loadAd must be called on the main UI thread.

Thank you

Yoann Hercouet
  • 17,894
  • 5
  • 58
  • 85
  • How about using RunOnUIThread from your background task. Usage explained here: http://stackoverflow.com/a/10135376/1683141 – Mdlc Mar 23 '14 at 12:04
  • What I need is to avoid using this UI Thread actually, this answer can't help me. – Yoann Hercouet Mar 26 '14 at 08:24
  • 1
    Having the same issue, introducing the new AdMob causes a massive delay in loading the App on some devices. About 3 seconds for Banner Ad and another 3 for Interstitial. This is just calling loadAd not actually displaying the Ad. – mbwasi Sep 30 '14 at 08:58

2 Answers2

1

Are you using the ad listener? try this:

interstitial = new InterstitialAd(this);
interstitial.setAdUnitId(Your-ad-id-here);

// Create ad request.
AdRequest adRequest = new AdRequest.Builder()
        .addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build();

// Begin loading your interstitial.
interstitial.loadAd(adRequest);

interstitial.setAdListener(new AdListener() {
    public void onAdLoaded() {
        displayInterstitial();
    }
}
Soatl
  • 10,224
  • 28
  • 95
  • 153
Jacob
  • 156
  • 1
  • 7
1

To avoid the slow down of your app start, delay the initialization until your activity has been loaded and is visible:

             mAdView.postDelayed(
                     new Runnable() {
                         @Override
                         public void run() {
                             mAdView.loadAd(adRequest);
                         }
                     }, 500
             );

See also AdMob causes delay in displaying fragments

Community
  • 1
  • 1
jekatt
  • 221
  • 2
  • 6