Call `MobileAds.initialize` on background thread
The Google Ads team now recommends calling MobileAds.initialize on a background thread to avoid ANRs.
Currently, this Plugin calls MobileAds.initialize on the UI thread.
https://github.com/googleads/googleads-mobile-flutter/blob/8e0834ee7f9b8f0ac1b886c5b3cae8937835c605/packages/google_mobile_ads/android/src/main/java/io/flutter/plugins/googlemobileads/GoogleMobileAdsPlugin.java#L349
https://github.com/googleads/googleads-mobile-flutter/blob/8e0834ee7f9b8f0ac1b886c5b3cae8937835c605/packages/google_mobile_ads/android/src/main/java/io/flutter/plugins/googlemobileads/FlutterMobileAdsWrapper.java#L39
Hi @blaugold, thanks for flagging. I've shared this with engineering to determine next steps.
Is there any workaround we can do on the flutter side while this lib is not updated? Can we call MobileAds.initialize in another Isolate safely?
Hi @Gilianp, we have a PR in the works https://github.com/googleads/googleads-mobile-flutter/pull/1165 that will be included in the next version. Please see until it's submitted
Hi @Gilianp, we have a PR in the works #1165 that will be included in the next version. Please see until it's submitted
Thanks @malandr2 , I will wait the next update!
I saw that this is implemented on all the examples folders:
<meta-data
android:name="com.google.android.gms.ads.flag.OPTIMIZE_AD_LOADING"
android:value="true" />
-
AppOpen: https://github.com/googleads/googleads-mobile-flutter/pull/1172/files#diff-ce2cacda361f60f008608daec0de85463f9c41d2b6ed8279242ff65b0b27c099
-
Banner: https://github.com/googleads/googleads-mobile-flutter/pull/1172/files#diff-065422729ac6c9b5950ec50e23c96293adb847f5b1317ba0f807a9ee4a14e07d
-
Interstitial: https://github.com/googleads/googleads-mobile-flutter/pull/1172/files#diff-edfadc71f4943e251704336e4e4c3e685c0844261a37ac8aa08b86be13345948
-
Mediation: https://github.com/googleads/googleads-mobile-flutter/pull/1172/files#diff-e56b43ee67852aaeb05046321fcebb7f988ebbe61d71812caa9f5f786fcbbaf9
5, 6, 7 e 8 is the same thing...
This shouldn't be added into the plugin android manifest too ? Otherwise everyone will have to implement this manually.
Hi @marcellocamara, those flags are optional. They are needed if you're not calling MobileAds.initialize on a background thread. When the google_mobile_ads plugin adds the background thread functionality, these flags will no longer be needed in our samples. See https://developers.google.com/admob/android/optimize-initialization#update_your_manifest_file for more details
This has been resolved in https://github.com/googleads/googleads-mobile-flutter/pull/1179 and will be included in the next release .5.2.0
@LTPhantom thanks
is that, seems there is InitializationStatus return, or related,
so the (my) app shouldn't await MobileAds.instance.initialize()?
thanks
update
thanks, resolved i knew that is about the platform