Automatically hide the AdView when there's no ad to show

  • Idea
  • Updated 2 years ago
Automatically hide the AdView when there's no ad to show. For example if there's no internet connection or whatever the reasons may be. I tried to do this myself, but the ads simply don't load when I hide it, be it via setting the height of the AdView to 0dip or via setVisibility(View.GONE). It doesn't do anything if I do that before knowing whether it got an Ad to show or not and doing it after that doesn't make a lot of sense as until then I'd have some ugly empty space in the app layout. I really like the idea of TapForTap, but the lack of this features and especially the fact that I cannot create it myself because of said reason is quite frustrating. I hope you'll soon have the time to include this feature into the SDK or at least give me a hint about how I could possibly do this myself.

Thanks in advance,
Lajos Ambrus
Photo of Dexter245D

Dexter245

  • 6 Posts
  • 0 Likes

Posted 3 years ago

  • 2
Photo of Dexter245D

Dexter245

  • 6 Posts
  • 0 Likes
Ok I did manage to do it now. Using the visibility setting of View makes the AdView do nothing at all. But it works if I set the height of it to 0 in the OnCreate method, call adView.loadAds() and then in didReceiveAd() call adView.loadAds() again the first time it gets into didReceiveAd(). It's ugly, but it's the only way I found to do this.
Photo of Tap for Tap SupportTF

Tap for Tap Support, Official Rep

  • 212 Posts
  • 9 Likes
Alternatively you can move it off screen, then move it on screen when the ads load. Unfortunately we need to handle the case where the AdView is on a tab or something that is not currently visible.

We will try to improve this in the future. Glad that you found a workaround for the time being.
Photo of Jaroslaw StakunJS

Jaroslaw Stakun

  • 2 Posts
  • 0 Likes
I'd like to go other way: keep AdView hidden until banner is loaded. I was playing with setVisibility and android:height set to wrap_content, but can't see loaded banner. I assume I should implement didReceiveAd() in listener to make AdView visible but don't know how. Any ideas?
Photo of Preceptor

Preceptor

  • 9 Posts
  • 0 Likes
I found a solution similar to Dexter but it ain't a pretty one. Tap for tap implemented a check in their SDK that if the visibility is set to gone or invisible the ad will not load. It is a legacy check for the previous SDK that gave you credit for the amount of times you showed your ad (and if it was invisible it would probably compute as well). Since the system is now a tap exchange, there is no need for such check anymore and a much cleaner solution would be to just set the visibily as gone until an ad is received.
Photo of Tap for Tap SupportTF

Tap for Tap Support, Official Rep

  • 212 Posts
  • 9 Likes
You are 100% correct Preceptor, and the latest versions of our SDK on Android (2.0.2) and iOS (2.0.1) have eliminated this check completely as it caused more trouble than it is worth.

We also need to do some work on the Android SDK to make use of the wrap_content setting for height, that way we will have a height of zero when there is no ad and will not take up space in the view hierarchy.
Photo of Preceptor

Preceptor

  • 9 Posts
  • 0 Likes
I was referring to the check of the view's visibility. Looks like that one wasn't removed and the ad still doesn't load if the view's visibility is "gone" or "invisible".
Photo of Tap for Tap SupportTF

Tap for Tap Support, Official Rep

  • 212 Posts
  • 9 Likes
Oh, my mistake! If adView.autoRollover is true and the AdView is not shown or the screen is off we delay loading ads. That check is still present and will not be removed so we don't waste resources when the device is locked, etc. If it's problematic we can change the specifics of the check so that it works well for everyone.

A workaround is to set adView.autoRollover = false and then enable it again later, if desired.
Photo of Preceptor

Preceptor

  • 9 Posts
  • 0 Likes
Hmmmm Interesting. It would be a cleaner solution if we turn that off until the first ad is received then just turn it on and set the view to visible.
Photo of Tap for Tap SupportTF

Tap for Tap Support, Official Rep

  • 212 Posts
  • 9 Likes
Note that you might want to call adView.loadAds() after enabling auto-rollover, as the timer that loads the next ad is set when the ad is loaded. Setting autoRollover after the fact won't have an effect.

autoRollover was intended to be slightly internal for use with mediation layers. Now that it's exposed perhaps we should add AdView.setAutoRollover() so that we can start/cancel the timer when it is turned on/off.