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

From reference :

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

I thought of calling this method from the Application class of my application as follows:

 public class MyApplication extends Application { // ... @Override public void onCreate() { super.onCreate(); MobileAds.initialize(getApplicationContext(), myAppId); } } 

In this case, is it considered good practice?

What is the right way to do this?

+6
source share
2 answers

Yes, that should be fine, and Google actually recommends doing it this way for other packages. For example, the Google Customization Guide for Google Analytics recommends initializing the global GoogleAnalytics object within the Application subclass.

So this is the right way to initialize MobileAds .

+6
source

Yes, your code looks perfect. Some Google examples recommend using Activity.onCreate, but this contradicts the doc :

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

This thread explains why you should call initialization. Soon: it speeds up the first call to AdView.loadAd. At the same time, I noticed that this slows down the creation of applications.

0
source

All Articles