Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Admob interstial loadAd function too slow

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

like image 355
Yoann Hercouet Avatar asked Mar 23 '14 07:03

Yoann Hercouet


1 Answers

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();
    }
}
like image 125
Jacob Avatar answered Oct 19 '22 17:10

Jacob