'Admob Android SDK 20.x : how to init InterstitialAd?

I update my app with Admob Android SDK 20.x.

In the previous versions of the SDK, it was possible to do something like this (in order to avoid to repeat the code if I want to load several interstitials):

private InterstitialAd interstitialAd1;
private InterstitialAd interstitialAd2;
private InterstitialAd interstitialAd3;
....

interstitialAd1 = new InterstitialAd(this);
interstitialAd2 = new InterstitialAd(this);
interstitialAd3 = new InterstitialAd(this);

loadInterstitial(interstitialAd1, "ca-app-pub-xxxxxx/aaaaaa");
loadInterstitial(interstitialAd2, "ca-app-pub-xxxxxx/bbbbbb");
loadInterstitial(interstitialAd3, "ca-app-pub-xxxxxx/cccccc");
....

 private void loadInterstitial(InterstitialAd interstitialAd, String interId) { 
 
           interstitialAd.setAdUnitId(interId);

            interstitialAd.setAdListener(new AdListener() {
                    @Override
                    public void onAdLoaded() {
                        // Code to be executed when an ad finishes loading.                        
                    }

                    @Override
                    public void onAdFailedToLoad(int errorCode) {
                        // Code to be executed when an ad request fails.                        
                    }

                    @Override
                    public void onAdOpened() {
                        // Code to be executed when the ad is displayed.                        
                    }

                    @Override
                    public void onAdLeftApplication() {
                        // Code to be executed when the user has left the app.                       
                    }

                    @Override
                    public void onAdClosed() {
                        // Code to be executed when the interstitial ad is closed.
                        loadInterstitial(interstitialAd);
                    }
                });            
          
        }
    }

With the new version of the SDK, I have got a compile error on:

interstitialAd1 = new InterstitialAd(this);

and also on :

interstitialAd1 = new InterstitialAd();

So when I see the code of the new SDK 20, I don't see how init several interstitials using the same or similar homemade method loadInterstitial.

How can I do? I don't want top copy/paste several times the Google code for every interstitial in my app...

Thanks for your help.



Solution 1:[1]

https://developers.google.com/admob/android/interstitial Here you can see that you can load ad by calling static method load of InterstitialAd class and you will receive the ad object in onAdLoaded callback. There is no need to create a new object manually, anymore!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Zeeshan Ali