15

Giving another chance to this comunity, my latest questions weren't ever answered

Well I have a game, the game have a pause button that hide most of the game interface to just show a pause text in the middle. There are so much free space, so I thought to put a banner at the bottom until the pause button is pressed again and resumes the game.

I know how to make banners work:

//When pause button is pressed
AdView adView = (AdView) this.findViewById(R.id.adView);
adView.setVisibility (View.VISIBLE);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);

But I don't know how to stop them when pause button is pressed again, just this:

adView.setVisibility (View.GONE);

I am pretty sure adView wont stop making requests with this line only.

I see some questions about this here but looks like they were using older admob SDK versions.

can somebody please, PLEASE help me?

Thanks.

1

2 Answers 2

25

You can try to Destroy and hide the AdView when button click and load the ad back when required.

    final AdView adView = (AdView) this.findViewById(R.id.adView);
    final AdRequest adRequest = new AdRequest.Builder().build();
    adView.loadAd(adRequest);

    button.setText("ClickMe");
    button.setOnClickListener(new View.OnClickListener() {
         boolean isPause = false;
        @Override
        public void onClick(View v) {
            if(isPause){
                adView.loadAd(adRequest);
                adView.setVisibility(View.VISIBLE);
                isPause = false;
            }else {
                adView.destroy();
                adView.setVisibility(View.GONE);
                isPause = true;
            }
        }
    });
8
  • Yes, works nice, the game show ads when I press pause and hide them properly when resume, Thanks a lot EDIT: But adViews aren't good for performance, the game looks slow when I press pause button, looks like those constant ad loads burns my device Commented May 9, 2014 at 0:31
  • Is it after AdView destroy ?
    – Libin
    Commented May 9, 2014 at 0:37
  • after loadAd and after destroy. I mean, pressing pause in any case slows the game Commented May 9, 2014 at 0:53
  • After loadAd it is possible, since the frequent update on UI. But destroy should not make it slow.
    – Libin
    Commented May 9, 2014 at 0:57
  • 1
    I checked Google API and it says: 'Destroy the AdView. This method should be called in the parent Activity's onDestroy() method. No other methods should be called on the AdView after destroy() is called.'. So the solution above is not right. I'll be trying adView.pause(). The only thing to remeber here is that activity onResume() also calls adView.resume() and that is something we would like to avoid when our adView is hidden. Additional boolean 'pause' flag required.
    – Dzik
    Commented May 23, 2014 at 11:03
1

You can count the ad opened methods call. and after it reached up to your limit you can make your ad view invisible.

    @Override
    public void onAdOpened() {
        // Code to be executed when an ad opens an overlay that
        // covers the screen.

        adClickedCount++;
        if (adClickedCount>2){
            mAdView.setVisibility(View.INVISIBLE);

        }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.