googlecodelabs / admob-native-advanced-feed

Apache License 2.0
53 stars 30 forks source link

Ads repeating on running the demo code. #11

Open yashasvi128 opened 5 years ago

yashasvi128 commented 5 years ago

I ran this code and the native ads in the list are sometimes working fine but most of the time they are like the bottom two screenshots. Can you please check whats wrong in this demo code? Tried on different devices but no luck :(

I just changed the layout of the ad for the demonstration of the issue, so I could show that multiple ads are showing on same page together.

image image

ingvictoriano commented 5 years ago

I'm having the same issue. I've tracked it down to adLoader.isLoading()

According to [documentation](https://developers.google.com/android/reference/com/google/android/gms/ads/AdLoader.html#isLoading())

public boolean isLoading () Returns true if the ad is loading. If multiple ads are requested, returns true until all ads finish loading.

But it appears that it sometimes returns true even if the 5 native ads aren't loaded. So on onUnifiedNativeAdLoaded the method insertAdsInMenuItems() is called multiple times.

Workaround is to change the if to

if (mNativeAds.size() == NUMBER_OF_ADS) {
     insertAdsInMenuItems();
}