MobileAds.initialize(context, appCode) is neccessary ?

5,824 views
Skip to first unread message

Dwyane Wade

unread,
Oct 27, 2016, 12:59:56 PM10/27/16
to Google Mobile Ads SDK Developers
Hi,

    I will update my admob sdk from Google-Play-Services to firebase. After I read the latest document of Admob, I find out there is a new Api was released called "MobileAds.initialize(context, appCode)".

   Now I have some questions:

   1. What does MobileAds.initialize(context, appCode) do? 

       + I did some tests, everything looks fine even if I don't invoke this api.  
       + I can't understand the explanation "Initialize the Mobile Ads SDK. The SDK will configure itself." in the link
 
   2. Should I invoke the api twice if I got two ad units from two admob accounts?



Thank you so much !!!

Veer Arjun Busani(Mobile Ads SDK Team)

unread,
Oct 27, 2016, 2:22:24 PM10/27/16
to Google Mobile Ads SDK Developers
Hi Dwayne,

1. What does MobileAds.initialize(context, appCode) do?
 
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. 

2. Should I invoke the api twice if I got two ad units from two admob accounts?

You only need to make one call irrespective of the number of AdMob accounts being used in your app. 

Thanks,
Arjun Busani
Mobile Ads SDK Team

Dwyane Wade

unread,
Oct 27, 2016, 10:02:37 PM10/27/16
to Google Mobile Ads SDK Developers
Hi Arjun,

Thanks for your kind reply.

As you say  "You only need to make one call irrespective of the number of AdMob accounts being used in your app.",  I can call MobileAds.initialize(context, appCode) with any application code that my two Admob accounts owned.

There are two questions still confuse me:

1. Is it ok to feed the api with a non-reasonable string, just like my name?

2. What is the intention of designing the api with an extra application code parameter?

Veer Arjun Busani(Mobile Ads SDK Team)

unread,
Oct 28, 2016, 9:54:03 AM10/28/16
to Google Mobile Ads SDK Developers
Hi Dwyane,

1. Is it ok to feed the api with a non-reasonable string, just like my name?

No. It would need your AdMob's AppCode.


2. What is the intention of designing the api with an extra application code parameter?

This is just for reporting purposes while initializing the SDK.

Thanks,
Arjun Busani
Mobile Ads SDK Team

Markus Wiederkehr

unread,
Nov 28, 2017, 4:03:29 AM11/28/17
to Google Mobile Ads SDK Developers
Hi,

I have noticed that MobileAds.initialize(context, appCode) takes nearly 200 ms to complete on my phone.

Would it be okay to call this asynchronously from a new Thread? Could we call it from Application.onCreate() instead of from an Activity?

Otherwise I don't really see the point. I mean if everything runs sequentially it does not really make a difference if this call takes 200 ms or if the first ad request takes 200 ms longer, does it?

Markus

Bharani Cherukuri (Mobile Ads SDK Team)

unread,
Nov 28, 2017, 3:09:39 PM11/28/17
to Google Mobile Ads SDK Developers
Hi Markus, 

You will be able to call the MobileAds.initialize() method in the onCreate() method. Please refer to our sample apps for more information. If you have any other specific concerns, please elaborate and I will be happy to assist you. 

Regards,
Bharani Cherukuri
Mobile Ads SDK Team

On Thursday, October 27, 2016 at 12:59:56 PM UTC-4, Dwyane Wade wrote:

Markus Wiederkehr

unread,
Dec 1, 2017, 5:42:05 AM12/1/17
to Google Mobile Ads SDK Developers
Hi Bharani,

Sorry for hijacking this old post, I should have probably started a new thread.

The original question was what does MobileAds.initialize() do and why do we need it. The answer was that "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".

The sample app calls initialize() and immediately after that it requests an ad. I suspect this is what most apps would do.

So my follow-up question is this, what is the advantage of having the initialize method? If the initialization and the first ad request are being executed sequentially there is no speed gain at all.

It would make sense if we could call the initialize method asynchronously, in a separate thread. It might also make sense to call it from Application.create().

On my system MobileAds.initialize() takes up to 800 ms to return. That has a considerable impact on the app's start time. And it is done on the UI thread!

Regards,
Markus

Bharani Cherukuri (Mobile Ads SDK Team)

unread,
Dec 1, 2017, 3:15:17 PM12/1/17
to Google Mobile Ads SDK Developers
Hi Markus, 

Thank you for contacting us. It is recommended that you initialize the Mobile Ads SDK by calling the MobileAds.initialize(). This needs to be called only once during the app launch. It is required to fire up the SDK. This might take a few milli seconds initially, doing so will reduce any latency caused to initialize the SDK, while loading the ads. You can call this method in the OnCreate() method. You may refer to this guide and our code samples for more information. 

Regards,
Bharani Cherukuri
Mobile Ads SDK Team

On Thursday, October 27, 2016 at 12:59:56 PM UTC-4, Dwyane Wade wrote:

Vivek Sharma

unread,
Apr 24, 2018, 3:49:55 AM4/24/18
to google-adm...@googlegroups.com
Hi Bharani,

The question that Can we call MobileAds.initialize() from background thread? is still unanswered.It is causing ANR in my application. I just want to know what impact will it have when I call this from background thread during onCreate of application class.

Thanks,
Vivek

mobileadssdk-a...@google.com

unread,
Apr 24, 2018, 11:26:45 AM4/24/18
to Vivek Sharma, Google Mobile Ads SDK Developers
Hi Vivek, 

Thank you for contacting us. It is recommended that you call the mobileAds.initialize() method to initialize the SDK. If this is not your concern, could you please elaborate? Could you also provide us steps to reproduce the ANR issue you're facing along with the complete stack trace? Since this is a very old thread, feel free to open a new thread along with these details, so we can take a look? 

Regards,
Bharani Cherukuri
Mobile Ads SDK Team

=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+ page:
    http://googleadsdeveloper.blogspot.com
    https://plus.google.com/115658573333388777174/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

Aman Kumar

unread,
Jun 19, 2018, 3:15:33 AM6/19/18
to Google Mobile Ads SDK Developers
Hi Bharani,

I am also facing ANR while doing mobileAds.initialize() call in main thread. Can we call it from background thread ? 
Also the issue has already been reported here https://github.com/googleads/googleads-mobile-unity/issues/688

Thanks
Aman

mobileadssdk-a...@google.com

unread,
Jun 19, 2018, 8:34:03 AM6/19/18
to Aman Kumar, Google Mobile Ads SDK Developers
Hello Aman, 

Thank you for reporting this. This is a known issue and our team is actively investigating this. I will keep you posted if I have any new updates to share.

Regards,
Bharani Cherukuri
Mobile Ads SDK Team

Irshad P I

unread,
Aug 9, 2018, 2:34:55 PM8/9/18
to Google Mobile Ads SDK Developers
Is this issue solved yet? Is it mandatory to call MobileAds.initialize?

mobileadssdk-a...@google.com

unread,
Aug 9, 2018, 5:37:11 PM8/9/18
to Irshad P I, Google Mobile Ads SDK Developers
Hello Irshad, 

For future reference, feel free to open a new thread for any new concerns for better tracking. That said, you will need to initialize the Mobile Ads SDK by calling MobileAds.initialize() with your AdMob App ID. Please check this guide for more information. 

Thanks,
Bharani Cherukuri
Mobile Ads SDK Team

=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+ page:
    http://googleadsdeveloper.blogspot.com
    https://plus.google.com/115658573333388777174/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

--

---
You received this message because you are subscribed to the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-admob-ads-sdk/17ae3c4f-4dd5-4eac-8e52-71923460d47d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Irshad P I

unread,
Aug 9, 2018, 10:44:56 PM8/9/18
to Google Mobile Ads SDK Developers
Yes. But that is causing an ANR in some devices and a delay of minimum 300 ms in all devices. I can't run it in a background thread either! What is the solution for this?.

mobileadssdk-a...@google.com

unread,
Aug 17, 2018, 2:59:42 PM8/17/18
to Irshad P I, Google Mobile Ads SDK Developers
Hello Irshad, 

That's right. Your app must initialize the Mobile Ads SDK using the MobileAds.initialize() method. This should be done only once and during the app launch. For the ANRs, could you share the following details to investigate the issue further?
  • Complete Stack Trace
  • Platform used (Android or Unity Android)
  • SDK version being used
  • Device details causing the ANR
  • Sample project where the issue is reproducible
This information will help our team to debug the issue. You can reply back via Reply privately to author.

Thanks,
Bharani Cherukuri
Mobile Ads SDK Team


=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+ page:
    http://googleadsdeveloper.blogspot.com
    https://plus.google.com/115658573333388777174/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

On 08/09/18 22:44:56 irsha...@gmail.com wrote:
Yes. But that is causing an ANR in some devices and a delay of minimum 300 ms in all devices. I can't run it in a background thread either! What is the solution for this?.

--

---
You received this message because you are subscribed to the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.

nanda kun

unread,
Aug 18, 2018, 12:46:31 AM8/18/18
to Google Mobile Ads SDK Developers
Hi, 

Regarding this issue, i have made tons of tests and here's what i have noticed : 

1. There's an obvious frame drop when calling MobileAds.Initialize(), and the main reason is the fact that it runs on the main thread. 

2. Imagine when using admob along with other networks without admob mediation, when you initialize all these networks it kills the cpu for a second or two at best and lead to ANRs on weak devices and slow connection. 

3. Do us all a favor, and do your stuff in a background thread, the last thing we need is frame drop and ANRs because of ads. 

I know that there are unity dependencies in the java adapter, but there are many mediation tools who have written their own adapters fro admob and it works perfectly with no lag nor crash.

Best Regards,

reda 

mobileadssdk-a...@google.com

unread,
Aug 20, 2018, 10:48:29 AM8/20/18
to nanda kun, Google Mobile Ads SDK Developers
Hello Reda, 

We understand your concern. We highly recommend that you call MobileAds.initialize() method in order to improve the app performance on the first request. You need to make this call only once when the app is initialized and before you attempt to load an ad. If you continue to have an issue with this, please share the following details to investigate the issue further.
  • Complete Stack Trace
  • Platform used (Android or Unity Android)
  • SDK version being used
  • Device details causing the ANR
  • Sample project where the issue is reproducible
This information will help our team to debug the issue. You can reply back via Reply privately to author.

Thanks,
Bharani Cherukuri
Mobile Ads SDK Team

=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+ page:
    http://googleadsdeveloper.blogspot.com
    https://plus.google.com/115658573333388777174/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

--

---
You received this message because you are subscribed to the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.

nanda kun

unread,
Aug 20, 2018, 12:59:26 PM8/20/18
to Google Mobile Ads SDK Developers
Hi, 

Thanks for the replay, 

As a developer, i honestly do only believe in A/B testing.

When you say something like it improves the app performance you should justify and explain how is it done! 

Cheers, 

Reda


 


mobileadssdk-a...@google.com

unread,
Aug 20, 2018, 5:00:26 PM8/20/18
to nanda kun, Google Mobile Ads SDK Developers
Hello Reda, 

Initializing the Mobile Ads SDK using the MobileAds.initialize() method will fire up the SDK and all the components required to load the ad at the start and will not cause any delay while loading the ads directly. This needs to be done only once, ideally at app launch. 

Let me know if you have any other questions. 

Regards,
Bharani Cherukuri
Mobile Ads SDK Team

=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+ page:
    http://googleadsdeveloper.blogspot.com
    https://plus.google.com/115658573333388777174/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

--

---
You received this message because you are subscribed to the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.

anonym

unread,
Dec 24, 2018, 1:50:54 PM12/24/18
to google-adm...@googlegroups.com

It is very sad and funny at the same time when Admob stuff just repeated next sentences here 100 hundred time to all questions users asked. 
All users call this method - MobileAds.initialize(), they have it, there is need to repeat them this again and again! Many users asked about calling MobileAds.initialize() in different thread (not main) and stuff again just replied the same boring sentences:
Reply all
Reply to author
Forward
0 new messages