diff --git a/packages/admob/android/src/main/java/io/invertase/firebase/admob/ReactNativeFirebaseAdMobInterstitialModule.java b/packages/admob/android/src/main/java/io/invertase/firebase/admob/ReactNativeFirebaseAdMobInterstitialModule.java index 98baaa58f5..4a42a1e470 100644 --- a/packages/admob/android/src/main/java/io/invertase/firebase/admob/ReactNativeFirebaseAdMobInterstitialModule.java +++ b/packages/admob/android/src/main/java/io/invertase/firebase/admob/ReactNativeFirebaseAdMobInterstitialModule.java @@ -63,6 +63,13 @@ private void sendInterstitialEvent(String type, int requestId, String adUnitId, @ReactMethod public void interstitialLoad(int requestId, String adUnitId, ReadableMap adRequestOptions) { + if (getCurrentActivity() == null) { + WritableMap error = Arguments.createMap(); + error.putString("code", "null-activity"); + error.putString("message", "Interstitial ad attempted to load but the current Activity was null."); + sendInterstitialEvent(AD_ERROR, requestId, adUnitId, error); + return; + } getCurrentActivity().runOnUiThread(() -> { InterstitialAd interstitialAd = new InterstitialAd(getApplicationContext()); interstitialAd.setAdUnitId(adUnitId); @@ -112,6 +119,10 @@ public void onAdClosed() { @ReactMethod public void interstitialShow(int requestId, ReadableMap showOptions, Promise promise) { + if (getCurrentActivity() == null) { + rejectPromiseWithCodeAndMessage(promise, "null-activity", "Interstitial ad attempted to show but the current Activity was null."); + return; + } getCurrentActivity().runOnUiThread(() -> { InterstitialAd interstitialAd = interstitialAdArray.get(requestId); diff --git a/packages/admob/android/src/main/java/io/invertase/firebase/admob/ReactNativeFirebaseAdMobRewardedModule.java b/packages/admob/android/src/main/java/io/invertase/firebase/admob/ReactNativeFirebaseAdMobRewardedModule.java index 21a43c1746..01feb83dd3 100644 --- a/packages/admob/android/src/main/java/io/invertase/firebase/admob/ReactNativeFirebaseAdMobRewardedModule.java +++ b/packages/admob/android/src/main/java/io/invertase/firebase/admob/ReactNativeFirebaseAdMobRewardedModule.java @@ -50,6 +50,13 @@ private void sendRewardedEvent(String type, int requestId, String adUnitId, @Nul @ReactMethod public void rewardedLoad(int requestId, String adUnitId, ReadableMap adRequestOptions) { + if (getCurrentActivity() == null) { + WritableMap error = Arguments.createMap(); + error.putString("code", "null-activity"); + error.putString("message", "Rewarded ad attempted to load but the current Activity was null."); + sendRewardedEvent(AD_ERROR, requestId, adUnitId, error, null); + return; + } getCurrentActivity().runOnUiThread(() -> { RewardedAd rewardedAd = new RewardedAd(getApplicationContext(), adUnitId); @@ -80,6 +87,10 @@ public void onRewardedAdFailedToLoad(int errorCode) { @ReactMethod public void rewardedShow(int requestId, String adUnitId, ReadableMap showOptions, Promise promise) { + if (getCurrentActivity() == null) { + rejectPromiseWithCodeAndMessage(promise, "null-activity", "Rewarded ad attempted to show but the current Activity was null."); + return; + } getCurrentActivity().runOnUiThread(() -> { RewardedAd rewardedAd = rewardedAdArray.get(requestId);