Where should i call MobileAds.initialize()?

Related searches

I have read https://developers.google.com/admob/android/quick-start?hl=en-US#import_the_mobile_ads_sdk

I need to initialize MobileAds using Code A in order to display AdMob AD.

I have some activities which need to display ADs, do I need to add code A in my all activities?

And more, why can the AdMob Ad be displayed correctly even if I remove

MobileAds.initialize(this, "YOUR_ADMOB_APP_ID")

Code A

import com.google.android.gms.ads.MobileAds;

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {

        // Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713
        MobileAds.initialize(this, "YOUR_ADMOB_APP_ID")

From the docs of MobileAds.initialize():

This method should be called as early as possible, and only once per application launch.

The proper way to do this would be to call it in the onCreate() method of the Application class.

If you don't have an Application class, simply create one, something like this:

class YourApp: Application() {

    override fun onCreate() {
        MobileAds.initialize(this, "YOUR_ADMOB_APP_ID")

You have to reference this class in AndroidManifest.xml, by setting the android:name attribute of the application tag:


    <!-- ... -->


And regarding your question:

why can the AdMob Ad be displayed correctly even if I remove

MobileAds.initialize(this, "YOUR_ADMOB_APP_ID")

Quote from Veer Arjun Busani of the Mobile Ads SDK team:

The Mobile Ads SDK take a few milliseconds to initialize itself and we now have provided this method to call it way before you even call your first ad. Once that is done, there would not be any added load time for your first request. If you do not call this, then your very first AdRequest would take a few milliseconds more as it first needs to initialize itself.

So basically if you do not call MobileAds.initialize(), then the first AdRequest will call it implicitly.

What is the proper way to call MobileAds.initialize()?, initialize()? � android. From the reference: This method should be called as early as possible, and only once per application launch� I dont think I am supposed to call MobileAds.Initialize(), right? Because I have never called this in the past, so I think it is called automatically internally. So my question is, is there a way to know if MobileAds is initialized? This way I can call SetApplicationVolume without throwing an exception.

MobileAds.initialize(this, "YOUR-APP-ID") has deprecated. Use the below code instead.

import android.app.Application
import com.google.android.gms.ads.MobileAds

class MyApp: Application() {

   override fun onCreate() {


When to call "MobileAds.initialize()", in the docs it says to call MobileAds.initialize as soon as possible, but what if we have to get consent from user , can we still call this method� public static void initialize ( Context context) Initializes the Google Mobile Ads SDK. Call this method as early as possible after the app launches to reduce latency on the session's first ad

Initializing MobileAds in Aplication context will cause error with InMobi mediation adapter

"Adapter Initialization status: Not Ready"

Tested with AdMob Test Suite.

Solution is to initialize MobileAds in Activity context.

MobileAds, Apps can import the Google Mobile Ads SDK with a Gradle dependency that points Before loading ads, have your app initialize the Mobile Ads SDK by calling� MobileAds. initialize (this,getString(R.string. ad_mob_app_id));} My Question is: 1) Do i need to call MobileAds. initialize (this,getString(R.string. ad_mob_app_id)); in both process? 2) In Andoid P Should i call MobileAds. initialize (this,getString(R.string. ad_mob_app_id)); after WebView. setDataDirectorySuffix ("ads_dir"); or before?

Get Started | Android, Could this be something from the android manifest file? still not working infect my app gets crash after few seconds of calling MobileAds. MobileAds.Initialize(): ambiguous overloads #1026. Open qbit86 opened this issue Oct 1, 2019 · 3 comments Ideally, with the new initialize call, you wait for the

MobileAds.Initialize() throws an exception � Issue #854 � googleads , MobileAds.Initialize(Context) has been un-deprecated. Google Ad Manager publishers should call this method when initializing their apps. AdMob publishers should still use MobileAds.Initialize(Context, String) and pass their application code. 9.6.0: 2016‑09‑22: Added the MediaView class for Native Ads Advanced video ads.

MobileAds. initialize (this, "YOUR_ADMOB_APP_ID"); Right now for testing purposes you can use the sample AdMob app ID provided by Google: ca-app-pub-3940256099942544~3347511713

  • No there is no needed to implement in all activity you have to just implement only on one activity .
  • I would rather have that few milliseconds on loading my first ad than on my app booting up :|