Closed MuhammadWaqasOfficial closed 3 weeks ago
In both cases you are calling the same API method. The difference you are seeing is a feature of C# which allows it to infer the type InitializationStatus
even if it is not included.
// All three of these snippets are the same.
MobileAds.Initialize(initStatus => { });
MobileAds.Initialize(InitializationStatus initStatus) => { });
MobileAds.Initialize(OnInit);
void OnInit(InitializationStatus initStatus);
[REQUIRED] Step 1: Describe your environment
[REQUIRED] Step 2: Describe the problem
Steps to reproduce:
What's the difference between these two lines because its conflicting in Admob Unity Plugin Docs. Sometime docs refers to MobileAds.Initialize(initStatus => { }); and sometime refers MobileAds.Initialize((InitializationStatus initStatus) => { });.
Why i am asking this? -> Its leading to potential ANRs and crashes which i will update later in discussion. How? -> calling load ads without knowing status of initStatus can leads to ANRs and crashes. MobileAds.Initialize((InitializationStatus initStatus) => { //call load ads, like LoadBannerAd(); LoadInterstitialAd(); LoadRewardedAd(); LoadRewardedInterstitialAd(); });
To resolve this either use MobileAds.Initialize(initStatus => { //call load ads }); where it goes in MobileAds.Initialize(initStatus => { //call load ads }); when initStatus is true (as far i understand)
Or use below approach as implemented in sample projects MobileAds.Initialize((InitializationStatus initStatus) => { if(initStatus !=nulll) { //call load ads } }); I am sharing this for my understanding and someone else making same mistake. I will facing huge anr spike. i will share my ANR and crashes stats after this. Please discard this post if not helpful.