create preload ad code example
Example: admob preload ad
**
* Created by Kirk-Patrick Brown on 10/26/2017.
*/
public class AdManager {
private static AdManager singleton;
public AdManager() {
}
public static AdManager getInstance() {
if (singleton == null) {
singleton = new AdManager();
}
return singleton;
}
public static void createAd(Context context) {
interstitialAd = new InterstitialAd(context);
interstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
interstitialAd.loadAd(new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build());
}
public static InterstitialAd getAd() {
return interstitialAd;
}
}
AdManager adManager = AdManager.getInstance();
adManager.createAd(MainActivity.this);
AdManager adManager = AdManager.getInstance();
InterstitialAd ad = adManager.getAd();
if (ad.isLoaded()) {
ad.show();
}