1

I have three activities, I want to show interstitial ad in the second and third Activity.

The user may open both Activity after each other, the result will be two interstitial ads shown.

How to avoid this behaviour?

Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98
kerollos
  • 87
  • 1
  • 13

1 Answers1

1

You can refer this (updated link) link which shows how you can use adbmob ads listener to get callbacks depending upon the present state of an ad.

Use AdListener to receive such callbacks, here's a sample of how you can do this.

   adView.setAdListener(new AdListener() {
        @Override
        public void onAdFailedToLoad(int errorCode) {
                        }

        @Override
        public void onAdClosed() {

        }

        @Override
        public void onAdOpened() {

        }

        @Override
        public void onAdLoaded(){
        }
      });

so, if an ad is already onscreen don't show another.

Ravinder Bhandari
  • 2,546
  • 21
  • 25
  • Thanks for your answer but the link is not working , and the method onPresentScreen not found – kerollos Dec 12 '16 at 20:02
  • Sorry mate, wasn't aware of changes in latest admob version, have changed the link and updated the answer, here you can use onAdOpened() and onAdClosed() for checking is ad is still visible or not.. and always load new ad inside onAdClosed() – Ravinder Bhandari Dec 12 '16 at 20:10
  • Thanks again but sorry , i want to detect whether it is open or not (boolean) like (isLoaded) but i don`t see (isShown). Do you have any idea how to do so ? – kerollos Dec 12 '16 at 20:43
  • You can manually remove your unwanted InterstitialAd instance from the view hierarchy: http://stackoverflow.com/questions/3805599/add-delete-view-from-layout. For example, Activity 2 has Interstitial A, and Activity 3 has Interstitial B. If the user opens both activities (2 --> 3), you can remove your interstitial ad that is opened on Activity 2 (by removing it from Activity 2's layout). – andzrev Dec 15 '16 at 18:51