googleads / googleads-mobile-android-examples

googleads-mobile-android
Apache License 2.0
1.67k stars 1.86k forks source link

Confused !!! There is two types of codes about initialize MobileAds and load ads in different example projects #643

Closed Gogogo-John closed 4 months ago

Gogogo-John commented 5 months ago

for appOpen, banner and rewardedVideo example project, your code is

private fun initializeMobileAdsSdk() {
    if (isMobileAdsInitializeCalled.getAndSet(true)) {
      return
    }

    // Initialize the Mobile Ads SDK.
    MobileAds.initialize(this) {}
    // Load an ad.
    loadRewardedAd()
  }

run MobileAds.initialize first, then call load-ad method immediately,

but in Interstitial, Native and rewardedInterstitial example project, your code is

private fun initializeMobileAdsSdk() {
    if (isMobileAdsInitializeCalled.getAndSet(true)) {
      return
    }

    // Initialize the Mobile Ads SDK.
    MobileAds.initialize(this) { initializationStatus ->
      // Load an ad.
      loadRewardedInterstitialAd()
    }
  }

run MobileAds.initialize first, but you call the load-ad method in initialize callback I`m so confused !!! So, which is the correct way ?

Gogogo-John commented 5 months ago

@NVentimiglia @dberlin @vjyanand @RedBrogdon

malandr2 commented 4 months ago

Hi @Gogogo-John, both are correct. Based on your developer setup, you can choose whatever way is best for your implementation. We are just highlighting the callback and no callback style of the initialize method.