Skip to content

Commit

Permalink
fix(android): race condition getting current activity
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorJohn authored Sep 10, 2023
1 parent 7c89579 commit b3a09e1
Showing 1 changed file with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
*/

import android.app.Activity;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import com.facebook.react.bridge.Arguments;
Expand Down Expand Up @@ -44,7 +45,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.json.JSONException;
Expand Down Expand Up @@ -167,13 +167,11 @@ private BaseAdView initAdView(ReactNativeAdView reactViewGroup) {
}
BaseAdView adView;
if (ReactNativeGoogleMobileAdsCommon.isAdManagerUnit(reactViewGroup.getUnitId())) {
if (((ReactContext) reactViewGroup.getContext()).getCurrentActivity() != null) {
Activity currentActivity = ((ReactContext) reactViewGroup.getContext()).getCurrentActivity();
if (currentActivity != null) {
// in order to display the debug menu for GAM ads we need the activity context
// https://github.com/invertase/react-native-google-mobile-ads/issues/188
adView =
new AdManagerAdView(
Objects.requireNonNull(
((ReactContext) reactViewGroup.getContext()).getCurrentActivity()));
adView = new AdManagerAdView(currentActivity);
} else {
return null;
}
Expand Down

0 comments on commit b3a09e1

Please sign in to comment.