From bf6884dc903154ae32daa50ce7983a9f014be781 Mon Sep 17 00:00:00 2001 From: Lulu Wu Date: Wed, 4 May 2022 15:52:47 -0700 Subject: [PATCH] Remove assertion when current activity is null Summary: Assertion failure would lead to a crash, in real world not being able to start an activity shouldn't crash - usually a navigation won't happen as expected, user could try again. Changelog: [Android][Changed] - Don't assert on current activity when call startActivityForResult Reviewed By: cortinico Differential Revision: D35746652 fbshipit-source-id: 0b77ca5a69b2f3f3b0b969d84980ed8290ac9b1f --- .../main/java/com/facebook/react/bridge/ReactContext.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactContext.java b/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactContext.java index 332a2849bd13ef..50cedcaa00073d 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactContext.java +++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactContext.java @@ -457,9 +457,11 @@ public boolean hasCurrentActivity() { */ public boolean startActivityForResult(Intent intent, int code, Bundle bundle) { Activity activity = getCurrentActivity(); - Assertions.assertNotNull(activity); - activity.startActivityForResult(intent, code, bundle); - return true; + if (activity != null) { + activity.startActivityForResult(intent, code, bundle); + return true; + } + return false; } /**