invertase / react-native-google-mobile-ads

React Native Google Mobile Ads enables you to monetize your app with AdMob.
https://docs.page/invertase/react-native-google-mobile-ads
Other
673 stars 135 forks source link

[🐛] Android: Improve ad object initialization #506

Closed birdofpreyru closed 7 months ago

birdofpreyru commented 9 months ago

What happened?

Below (and, if applicable, in other similar places in the Android code, where ad objects are created): https://github.com/invertase/react-native-google-mobile-ads/blob/c0c3df6874033b98b6d7ba71643b486af394a9b4/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsBannerAdViewManager.java#L182

An Activity instance rather than Context should be passed into the AdView constructor, as per AdMob Mediation instructions image

P.S.: I guess, I can make a PR later. Though looking at the existing code just above, where it checks whether currentActivity might be null, but does not check for the context to be null, I'd like to check with @dylancom first, if he knows whether it is possible that the current activity is indeed null at that point? If yes, what would be better, to return null if it is null, or just init with context instead, as a fallback?

Platforms

Only on Android

React Native Info

N/A

Are your using Typescript?

package.json

N/A

app.json

N/A

ios/Podfile

No response

android/build.gradle

No response

android/app/build.gradle

No response

android/settings.gradle

No response

AndroidManifest.xml

No response

mikehardy commented 9 months ago

All I know about "Activity" in react-native is that it can be null, you can never be sure that the Activity wasn't destroyed even though your code is still executing because of the async nature of the native/javascript bridge (which is Application-scoped if I understand correctly - while the Activity can come and go)

So this is kind of a fundamental mismatch between what mediation needs and how react-native works. I'm not sure how to harmonize them, all I know for certain is that your Activity can become invalid / null when you least expect it and that needs to be handled

github-actions[bot] commented 8 months ago

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

birdofpreyru commented 8 months ago

Thanks @github-actions , but let's keep it open for now.

github-actions[bot] commented 7 months ago

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

birdofpreyru commented 7 months ago

not stale

mikehardy commented 7 months ago

:tada: This issue has been resolved in version 12.11.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: