Skip to content

Commit f4fdf4b

Browse files
luluwu2032facebook-github-bot
authored andcommitted
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
1 parent c0e0446 commit f4fdf4b

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java

+14-9
Original file line numberDiff line numberDiff line change
@@ -345,16 +345,21 @@ private void showNewError(
345345
@Override
346346
public void run() {
347347
Activity context = mReactInstanceDevHelper.getCurrentActivity();
348-
if (mRedBoxDialog == null || context != currentActivity) {
349-
if (context == null || context.isFinishing()) {
350-
FLog.e(
351-
ReactConstants.TAG,
352-
"Unable to launch redbox because react activity "
353-
+ "is not available, here is the error that redbox would've displayed: "
354-
+ message);
355-
return;
356-
}
348+
if (context != null && !context.isFinishing() && currentActivity != context) {
357349
currentActivity = context;
350+
// Create a new RedBox when currentActivity get updated
351+
mRedBoxDialog =
352+
new RedBoxDialog(currentActivity, DevSupportManagerBase.this, mRedBoxHandler);
353+
}
354+
if (currentActivity == null || currentActivity.isFinishing()) {
355+
FLog.e(
356+
ReactConstants.TAG,
357+
"Unable to launch redbox because react activity "
358+
+ "is not available, here is the error that redbox would've displayed: "
359+
+ message);
360+
return;
361+
}
362+
if (mRedBoxDialog == null) {
358363
mRedBoxDialog =
359364
new RedBoxDialog(currentActivity, DevSupportManagerBase.this, mRedBoxHandler);
360365
}

0 commit comments

Comments
 (0)