Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call MobileAds.initialize on background thread #1135

Closed
blaugold opened this issue Jul 15, 2024 · 8 comments
Closed

Call MobileAds.initialize on background thread #1135

blaugold opened this issue Jul 15, 2024 · 8 comments
Assignees
Labels
in triage Issue currently being evaluated

Comments

@blaugold
Copy link

blaugold commented Jul 15, 2024

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.

flutterMobileAds.initialize(context, new FlutterInitializationListener(result));

@malandr2
Copy link
Collaborator

Hi @blaugold, thanks for flagging. I've shared this with engineering to determine next steps.

@malandr2 malandr2 added the in triage Issue currently being evaluated label Jul 15, 2024
@Gilianp
Copy link

Gilianp commented Sep 5, 2024

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?

@malandr2
Copy link
Collaborator

malandr2 commented Sep 5, 2024

Hi @Gilianp, we have a PR in the works #1165 that will be included in the next version. Please see until it's submitted

@Gilianp
Copy link

Gilianp commented Sep 5, 2024

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!

@marcellocamara
Copy link

marcellocamara commented Sep 14, 2024

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" />
  1. AppOpen: https://github.com/googleads/googleads-mobile-flutter/pull/1172/files#diff-ce2cacda361f60f008608daec0de85463f9c41d2b6ed8279242ff65b0b27c099

  2. Banner: https://github.com/googleads/googleads-mobile-flutter/pull/1172/files#diff-065422729ac6c9b5950ec50e23c96293adb847f5b1317ba0f807a9ee4a14e07d

  3. Interstitial: https://github.com/googleads/googleads-mobile-flutter/pull/1172/files#diff-edfadc71f4943e251704336e4e4c3e685c0844261a37ac8aa08b86be13345948

  4. 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.

@malandr2
Copy link
Collaborator

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

@malandr2
Copy link
Collaborator

malandr2 commented Oct 7, 2024

This has been resolved in #1179 and will be included in the next release .5.2.0

@malandr2 malandr2 closed this as completed Oct 7, 2024
@peterweb2005
Copy link

peterweb2005 commented Oct 9, 2024

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in triage Issue currently being evaluated
Projects
None yet
Development

No branches or pull requests

6 participants