1

How can you disable admob on a page: this is how i implemented it in XML and main activity (of course i have string with Ad-id:

XML below:

   <LinearLayout
    android:layout_alignParentBottom="true"
    android:id="@+id/AdsArea"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:orientation="vertical">
</LinearLayout>

Main activity below:

  private void loadGoogleAds() {
        LinearLayout rootLayout = (LinearLayout) findViewById(R.id.AdsArea);
        AdView adView = new AdView(this);
        adView.setAdSize(AdSize.BANNER);
        adView.setAdUnitId(getString(R.string.ad_unit_id));
        rootLayout.addView(adView, 0);
        AdRequest adRequest = new AdRequest.Builder().build();
        adView.loadAd(adRequest);
To.vi
  • 43
  • 6

1 Answers1

1

As you are adding AdView programatically, I think to remove ads don't call loadGoogleAds() from your Activity.

OR, you can hide AdView using:

if (adView.getVisibility() == AdView.VISIBLE)
    adView.setVisibility(View.GONE);

OR, remove adView from rootLayout using:

rootLayout.removeViewAt(0); 
Ferdous Ahamed
  • 21,438
  • 5
  • 52
  • 61
  • so this will remove the ad in one page not the whole ad right? – To.vi May 06 '17 at 00:28
  • (It says can't resolve to method for "setVisibility" -main goal is to stop call of admob or any activity when when user leave the admob viewing activity – To.vi May 06 '17 at 01:12
  • Following are the errors: Error:(40, 25) error: expected Error:(40, 35) error: expected Error:Execution failed for task ':sdk:compileReleaseJavaWithJavac'. > Compilation failed; see the compiler error output for details. – To.vi May 06 '17 at 01:19
  • Thanks your updated answer works to hide Ad. But i was trying to use to to solve the problem i am having where when i add admob to my app it crashes as per this question(http://stackoverflow.com/questions/43766980/when-sending-message-app-crashes-with-this-error-it-works-fine-prior-to-admob) how can i get the backendless not to notice the admob so that it won't crash – To.vi May 06 '17 at 01:39
  • I have seen your question. It seems different from admob. I will try to give a solution. But i think my answer resolved your current question. So its better to mark my answer as accepted and if seems useful give an up vote also. Thanks in advance :) – Ferdous Ahamed May 06 '17 at 02:27
  • I have marked your answer as acceted for the question here and thanks for the help :) – To.vi May 08 '17 at 13:28
  • Happy to help you. You can give an up-vote if my answer seems useful to you. Thanks in advance :) – Ferdous Ahamed May 08 '17 at 13:38