What is the proper way to call MobileAds.initialize()?

Yes this should be fine, and Google actually recommends doing it this way for other packages. For example, in Google's setup guide for Analytics, they recommend initializing the global GoogleAnalytics object inside an Application subclass.

So yes, this is a proper way to initialize MobileAds.


Yes, your code looks perfect. Some google examples recommend to use Activity.onCreate, but that contradicts to the doc:

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

This thread explains why you should call initialize. Shortly: it speeds up first call AdView.loadAd. At the same time I noticed that it slows down application creation.


Calling MobileAds.initialize() is optional and MobileAds.initialize() executes on Main Thread. So calling it in the onCreate of the Activity will create a lag in the display of your Activity.

I tested it on OnePlus 6 and execution of MobileAds.initialize() is taking 400-500 ms.

My Implementation is to call MobileAds.initialize() in a Separate Thread created in the onCreate method of the Application Instance.

public class CustomApplication extends MultiDexApplication {
    @Override
    public void onCreate() {
        Thread thread = new Thread() {
            @Override
            public void run() {
                MobileAds.initialize(context, initializationStatus -> {
                    Logger.log("MobileAds init");
                });
                //Other heavy task
            }
        };
        thread.start();
    }
}

Tags:

Android