zap
zap

Reputation: 221

Disable admob ads after a click?

Hi All ~ Is that possible to disabled admob ads after clicked ? I tried with this code but nothing happened, can anyone please help me out ? Thanks in advance

    final LinearLayout layout = ( LinearLayout )findViewById( R.id.adslayout ) ;
    final AdView adView = new AdView( this, AdSize.BANNER, "a11111111b9041" ) ;
    layout.addView( adView ) ;
    adView.setVisibility( View.VISIBLE ) ;
    adView.loadAd( new AdRequest() ) ;

    adView.setOnClickListener( new View.OnClickListener()
    { 
       public void onClick( View v ) 
      {
            layout.removeAllViews() ;
            adView.setVisibility( View.GONE ) ;
             ed.putBoolean( "adsClicked", true ) ;
             ed.commit() ;
      } // onClick() 
    }  );

Upvotes: 1

Views: 5691

Answers (3)

sotiris
sotiris

Reputation: 345

Override onAdLeftApplication and set a variable. Then you can skip loading ads depending on that variable

interstitial = new InterstitialAd(this);
interstitial.setAdUnitId(MY_AD_UNIT_ID);

interstitial.setAdListener(new AdListener() {
   @Override
   public void onAdLeftApplication(){
       user_has_clicked_ads = true;
   }

check documentation https://developers.google.com/android/reference/com/google/android/gms/ads/AdListener.html#onAdLeftApplication()

Upvotes: 0

Chris
Chris

Reputation: 950

If your class implements AdListener, you can put your disable code into onDismissScreen(). This method is called when the user closes the advertisement and returns to your app.

For example:

public class Advertisement implements AdListener{

    // more code here

    @Override
    public void onDismissScreen(Ad arg0) {
        mainLayout.removeView(adView);
    }

    // more code here

}

Upvotes: 2

Muzikant
Muzikant

Reputation: 8090

There is one undocumented (?) method for the AdView widget which is stopLoading. I think that should do the job.

Simply hiding the widget does not stop it from keep requesting Ads.

Upvotes: 0

Related Questions