Admob Ads global initialization

47 views
Skip to first unread message

Tomáš Kuba

unread,
Jul 31, 2024, 12:26:29 PMJul 31
to Google Mobile Ads SDK Developers
Hi all, I would like to finally find a solution to the "issue" which I am about to describe here.

I use AdMob ads in my Android app. I am creating them in following recommended way:

    override fun initAds(activity: Activity, adLayout: LinearLayout) {
        adLayout.removeAllViews()
        val uiAdView = AdView(activity)
        uiAdView.setAdSize(getAdSize(activity))
        uiAdView.adUnitId = // AD UNIT ID HERE
        adLayout.addView(uiAdView)
        uiAdView.loadAd(prepareAdRequest()) 
    }

This way, ad loads as expected - after a few seconds, the ad is displayed (it takes some time to load an ad). However, in case I go to another Activity, the process is the same, so there are few seconds during which the ad is not displayed. Can somebody provide a better approach how to solve this? All AdMob guidelines are more or less recommending to use the approach I described, but I doubt it is the best approach to work with ads.

I have thought about putting initAds to Application (singleton) class to have it available everywhere so I can obtain the same adView for the different activities. However, the AdView creation requires context, so this would not work. 

Another approach would be to reimplement the app completely using fragments and have only one Activity, which would create the AdView, however I do not have possibility to reimplement the whole application. Thank you for your ideas and advices. 


Mobile Ads SDK Forum Advisor

unread,
Jul 31, 2024, 2:33:17 PMJul 31
to tomas....@gmail.com, google-adm...@googlegroups.com

Hi,

Could you try once by enabling Ad Inspector ? And then share the export request and response file generated from Ad Inspector to us. Additionally share below details via reply to author option for further investigation:

  • app ID
  • ad unit ID
  • Mobile Ads SDK version
  • Sample project reproducing the issue

 If the file(s) you are looking to share are less than 25mb in total you can attach them to this case on your next reply. If you are having trouble attaching your file to this case or if your file(s) are larger than 25mb, you can share your files by performing the following steps:

1. Navigate to

https://docs.google.com/forms/d/e/1FAIpQLSfkAiXMeYP-fw1W3Z-tT9uwmATEKO5X6S-th0gR2ezdKaaqfg/viewform?usp=pp_url&entry.400550049=Mobile+Ads+SDK&entry.460850823=5004Q00002vEN4tQAG&entry.80707362=00260350

2. Fill out all fields, and attach your file(s).

3. Please reply back on this thread when you have uploaded your file(s). Please do not share this link.

Note:You can export the ad response only after you add your test device in the AdMob UI.

For detail info refer to this AdInspector document.

 
This message is in relation to case "ref:!00D1U01174p.!5004Q02vEN4t:ref" (ADR-00260350)

Thanks,
 
Google Logo Mobile Ads SDK Team


Tomáš Kuba

unread,
Aug 1, 2024, 7:15:24 AMAug 1
to Google Mobile Ads SDK Developers
This is not an issue with the ads itself. It is a question to find a proper way of displaying ads.

Mobile Ads SDK Forum Advisor

unread,
Aug 1, 2024, 12:43:31 PMAug 1
to tomas....@gmail.com, google-adm...@googlegroups.com
Hi,

You can find sample example for each ad format implementation here. Make sure you follow all the AdMob policies and restrictions for own implementations. 
Reply all
Reply to author
Forward
0 new messages