Difference Between Adding AdView Before vs. After loadAd() in AdMob Banner

83 views
Skip to first unread message

Sunho Kim

unread,
Mar 4, 2025, 1:21:40 AM3/4/25
to Google Mobile Ads SDK Developers
Hi everyone,

I'm currently using AdMob banner ads in my Android app and have a question about when to add the AdView to the layout.


So far, I’ve been using Method 1:

adContainerView.addView(adView)
adView.loadAd(adRequest)


However, I want to switch to Method 2 for better ad loading management:

adView.loadAd(adRequest)
adView.adListener = object : AdListener() {
    override fun onAdLoaded() {
        super.onAdLoaded()
        adContainerView.addView(adView)
    }
}


My Questions:
Is there any difference between these two approaches in terms of performance or best practices?
With Method 1, I noticed that every time the banner refreshes, onAdLoaded() is triggered. However, in Method 2, onAdLoaded() does not get triggered again after the initial load. Why does this happen?
I want to make sure that switching to Method 2 won’t cause any unexpected issues.

Thanks in advance!

Mobile Ads SDK Forum Advisor

unread,
Mar 4, 2025, 9:41:03 AM3/4/25
to den...@gmail.com, google-adm...@googlegroups.com

Hi,

Thank you for contacting the Mobile SDK support team.

When you load the ads from the first method then an adView is added to the adContainerView before the ad is loaded after that ad request is initiated.

But when you are using method two to load the ads in this first we load the ad. After that we added the container to show the ads.

In both cases the onAdLoaded() method is called after every refresh.but it looks like you are binding the container every time. so I would suggest not binding the container a second time. Also you can try to put logs before bind the container to see onAdLoaded() method is called.

Thanks,
 
Google Logo Mobile Ads SDK Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5
[2025-03-04 14:39:41Z GMT] This message is in relation to case "ref:!00D1U01174p.!5004Q02vH5sR:ref" (ADR-00291286)



Sunho Kim

unread,
Mar 4, 2025, 5:52:57 PM3/4/25
to Google Mobile Ads SDK Developers
So, if I only add the banner container initially when using the second method, can I still use the AdMob Mobile SDK in a proper way? Does this guarantee normal operation?

Mobile Ads SDK Forum Advisor

unread,
Mar 4, 2025, 7:55:56 PM3/4/25
to den...@gmail.com, google-adm...@googlegroups.com

Hi, 

As per sample code, It is not require to addView(adView) again when automatically refreshing the banner ads.
If you will add adView again without removeAllViews, you may face below issue during automatically refresh in adLoaded listener.
Error Message: “The specified child already has a parent. You must call removeView() on the child's parent first. “

I would suggest to removeAllViews first then addView(adView) again.
Let me know you  face any issues related to ad not refreshing in the view.


Thanks,
 
Google Logo Mobile Ads SDK Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5

[2025-03-05 00:54:58Z GMT] This message is in relation to case "ref:!00D1U01174p.!5004Q02vH5sR:ref" (ADR-00291286)



Reply all
Reply to author
Forward
0 new messages