Domanda

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.

È stato utile?

Soluzione

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;
            }
        }
    });

Altri suggerimenti

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);

        }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top