I am loading Interstitial ad in baseactivity's oncreate method, This baseactivity is extended by all other activities of the app so every time I start a new activity a new interstitial is being loaded even if there's one loaded already.
private InterstitialAd mInterstitialAd; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); createAdhere(); } public void createAdhere () { AdRequest adRequest = new AdRequest.Builder().build(); InterstitialAd.load(BaseActivity.this, "ca-app-pub-3940256099942544/8691691433", adRequest, new InterstitialAdLoadCallback() { @Override public void onAdLoaded(@NonNull InterstitialAd interstitialAd) { Toast.makeText(BaseActivity.this, "Ad Loaded", Toast.LENGTH_LONG).show(); mInterstitialAd = interstitialAd; mInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback(){ @Override public void onAdDismissedFullScreenContent() { // Called when fullscreen content is dismissed. Toast.makeText(BaseActivity.this, "fullscreen content is dismissed.", Toast.LENGTH_LONG).show(); } @Override public void onAdFailedToShowFullScreenContent(AdError adError) { // Called when fullscreen content failed to show. Toast.makeText(BaseActivity.this, "fullscreen content failed to show.", Toast.LENGTH_LONG).show(); } @Override public void onAdShowedFullScreenContent() { // Called when fullscreen content is shown. // Make sure to set your reference to null so you don't // show it a second time. mInterstitialAd = null; Toast.makeText(BaseActivity.this, "fullscreen content is shown.", Toast.LENGTH_LONG).show(); } }); } @Override public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) { Toast.makeText(BaseActivity.this, "Ad Failed to Load", Toast.LENGTH_LONG).show(); } }); }
How to load them only once?
https://stackoverflow.com/questions/66964020/how-to-avoid-loading-admob-interstitial-ad-if-one-is-already-loaded April 06, 2021 at 02:58PM
没有评论:
发表评论