Skip to content

Commit

Permalink
fix(android): use currentActivity in initialize if !null, aids use of…
Browse files Browse the repository at this point in the history
… mediation adapters (#664)

* Opportunistically use currentactivity

Required for Unity Ads to function, as far as I can see shouldn't effect anything else

* docs: add note about maybe-dangerous use of currentActivity

Hopefully no one will ever read it or care!
But if there are crashes, our current understanding and reasoning is now noted for future maintainer use

---------

Co-authored-by: Mike Hardy <[email protected]>
  • Loading branch information
TaylorDale and mikehardy authored Dec 2, 2024
1 parent 2aa29f0 commit 410bcdc
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ class ReactNativeGoogleMobileAdsModule(
@ReactMethod
fun initialize(promise: Promise) {
MobileAds.initialize(
reactApplicationContext,
// in react-native, the Activity instance *may* go away, becoming null after initialize
// it is not clear if that can happen here without an initialize necessarily following the Activity lifecycle
// it is not clear if that will cause problems even if it happens, but users that have widely deployed this
// with the use of currentActivity have not seen problems
// reference if it needs attention: https://github.com/invertase/react-native-google-mobile-ads/pull/664
currentActivity ?: reactApplicationContext,
OnInitializationCompleteListener { initializationStatus ->
val result = Arguments.createArray()
for ((key, value) in initializationStatus.adapterStatusMap) {
Expand Down

0 comments on commit 410bcdc

Please sign in to comment.