6

I hide admob adview by view.gone:

//adView.setClickable(false);
//adView.clearFocus();
//adView.setEnabled(false);
//adView.setFilterTouchesWhenObscured(true);
//adView.setFocusable(false);
//adView.setFocusableInTouchMode(false);
adView.setVisibility(View.GONE);
adView.startAnimation( animation );

This hides the ad, but the adview itself is still touchable, so if I touch the adview's space, it still opens the browser and redirects me to the ad, although the ad itself is not visible.

How to disable the touch event too? I've tried all lines above but none of them worked.

Any advice?

Tamas
  • 353
  • 1
  • 4
  • 9

3 Answers3

6

Setting adView.setVisibility(View.GONE) and removing the AdMob view from the view hierarchy will hide the ad and prevent user interaction in most cases.

Don't forget to end the AdView lifecycle when the Activity displaying the ad is finished (destroyed). From the AdMob SDK Javadoc:

public void destroy()

Destroys the AdView. The AdView should no longer be used after this method is called.

Make a call to destroy() in the Activity's onDestroy() callback:

@Override
public void onDestroy() {
    if (adView != null) {
        adView.destroy();
    }
super.onDestroy();
}
mjama
  • 2,650
  • 2
  • 22
  • 24
  • adView has type AdView. Simple View has no destroy() methode. – Mark Sep 23 '13 at 18:31
  • @Mark `AdView` has its own defined `destroy()` method. – Vektor88 Feb 25 '14 at 10:10
  • 1
    @mjama should I call the .destroy() too if I've created the AdView via XML? In the guide seems like I don't need to call destroy: https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals?hl=it#play – Accollativo Jun 24 '14 at 15:28
5

Try to use setOnTouchListener and Override onTouch like you want. Also you can use removeView():

LinearLayout linLay = (LinearLayout)findViewById(R.id.ad_layout);
linLay.removeView(adView); 
LinearLayout.LayoutParams params = new  LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
linLay.addView(adView, params);

and add it back when you need.

jumper0k
  • 2,166
  • 2
  • 22
  • 31
0
final com.google.ads.AdView ad = (AdView) findViewById(R.id.rect_ad);
   if ( ad != null) {
            ad.stopLoading();
            ad.destroy();
            getWindowManager().removeView(ad);
   }

even this code doesn't destroy AdMob =((( I have it's Handler and WebView in memory holding my activity

Andrew Matiuk
  • 924
  • 1
  • 7
  • 21
  • An workaround is to no rely on the XML version of the AdView, but create the view programmatically and add it a container. This way you can use the application context. If you use the XML version it will use the Activity context which will be prone to memory leaks. (I've also discovered this recently) – Ionut Negru Jan 11 '17 at 09:03