Admob interstial loadAd function too slow

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

Interstitial mode works well, but the following call:

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

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

What can I do to avoid this? I followed just such an example provided by Google here .

FYI I tried to load an ad in the background using AsyncTask , but this is not possible:

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

thanks

+7
android google-play-services admob
source share
2 answers

Do you use an ad listener? try the following:

 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(); } } 
+1
source share

To avoid slowing down the launch of the application, delay initialization until your activity is loaded and visible:

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

See also AdMob causes fragment display delay

+1
source share

All Articles