How to hide / disable admob adview?

I hide admob adview from 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 form of advertising is still tangible, so if I touch the area of โ€‹โ€‹the advertising space, it still opens the browser and redirects me to the ad, although the ad itself is not visible.

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

Any tips?

+6
source share
3 answers

Try using setOnTouchListener and Override onTouch as you want. You can also 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.

+4
source

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

Remember to end the AdView life cycle when the action showing the ad is completed (destroyed). From the AdMob Javadoc SDK:

public void destroy ()

Destroys AdView. AdView will no longer be used after calling this method.

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

 @Override public void onDestroy() { if (adView != null) { adView.destroy(); } super.onDestroy(); } 
+5
source
 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 does not destroy AdMob = (((I have a Handler and a WebView in memory, where my actions are stored.

0
source

Source: https://habr.com/ru/post/913871/


All Articles