Admob and Xamarin Forms

I had noticed that the advert on the Favourites screen had disappeared on my android phone. I spent a good day trying to fix it and I was most annoyed when I found out what the issue was.

Looking through the debug logging I had added, it started to display the ad but never finished. I googled anything that was logged and drew lots of blanks. Eventually after a good few hours searching I came across a throw away comment on the Xamarin forum.

It turned out that the advert was there all along, in fact if you launch the app and turn the phone 90 degrees, the advert appears. On the initial launch, the screen wasn’t laying itself out properly and the ad was there but with no height. Some people suggested setting the height of the view where the ad appears to a fixed number. Phone and tablet ads were both different heights. This was ok, except if there were no ads to display. Then you would have a blank space where the ad should be.

In the end I fixed it by displaying the page and then after a second hiding and showing the advert. This caused the visible screen to re-lay itself out and, hey presto, the advert was visible. This fix was wrapped in some IF statements as it appeared to be only Android 27+ where this happened.

Leave a comment

Your email address will not be published. Required fields are marked *