From f4fdf4b55e4489c21f4552b4ac01ef253c038b2d Mon Sep 17 00:00:00 2001 From: Lulu Wu Date: Mon, 20 Sep 2021 14:13:06 -0700 Subject: [PATCH] Fix currentActivity being null when launching Redbox Summary: Try to reuse currentActivity when the new context from "mReactInstanceDevHelper.getCurrentActivity()" is null to fix "Unable to launch redbox because react activity is not available..." Changelog: [Android][Fixed] - Fix currentActivity being null when launching Redbox Reviewed By: philIip Differential Revision: D30942434 fbshipit-source-id: faf03390adc545376f3cec223eac5a16bf8233ea --- .../devsupport/DevSupportManagerBase.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java index e0de5489387..7a7c8c21c52 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java @@ -345,16 +345,21 @@ public abstract class DevSupportManagerBase implements DevSupportManager { @Override public void run() { Activity context = mReactInstanceDevHelper.getCurrentActivity(); - if (mRedBoxDialog == null || context != currentActivity) { - if (context == null || context.isFinishing()) { - FLog.e( - ReactConstants.TAG, - "Unable to launch redbox because react activity " - + "is not available, here is the error that redbox would've displayed: " - + message); - return; - } + if (context != null && !context.isFinishing() && currentActivity != context) { currentActivity = context; + // Create a new RedBox when currentActivity get updated + mRedBoxDialog = + new RedBoxDialog(currentActivity, DevSupportManagerBase.this, mRedBoxHandler); + } + if (currentActivity == null || currentActivity.isFinishing()) { + FLog.e( + ReactConstants.TAG, + "Unable to launch redbox because react activity " + + "is not available, here is the error that redbox would've displayed: " + + message); + return; + } + if (mRedBoxDialog == null) { mRedBoxDialog = new RedBoxDialog(currentActivity, DevSupportManagerBase.this, mRedBoxHandler); }