Skip to content

Commit

Permalink
Check if mCurrentActivity is set according to LifecycleState (#23336)
Browse files Browse the repository at this point in the history
Summary:
Issues: Related to  #13439
react-native-website:Related to PR [#792](facebook/react-native-website#792)
solution: #13439 (comment)

When we integration with Existing  Android Apps.and set LifecycleState  is `LifecycleState.RESUMED`.
It's lead to `mCurrentActivity`  is null .

At this time , the behave of set `mCurrentActivity ` which  is unexpectedly.

## Changelog
[Android] [Fixed] - Check if mCurrentActivity is set according to LifecycleState
Pull Request resolved: #23336

Differential Revision: D14298654

Pulled By: cpojer

fbshipit-source-id: 5cc17539a51154faeb838349b068d92511946f79
  • Loading branch information
RoJoHub authored and facebook-github-bot committed Jun 12, 2019
1 parent 38adb8e commit fb550e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,14 @@ public void loadBundle(final ReactInstanceSpecForTest spec, String bundleName, b
} else {
builder.addPackage(new MainReactPackage());
}
/**
* The {@link ReactContext#mCurrentActivity} never to be set if initial lifecycle state is resumed.
* So we should call {@link ReactInstanceManagerBuilder#setCurrentActivity}.
*
* Finally,{@link ReactInstanceManagerBuilder#build()} will create instance of {@link ReactInstanceManager}.
* And also will set {@link ReactContext#mCurrentActivity}.
*/
builder.setCurrentActivity(this);
builder
.addPackage(new InstanceSpecForTestPackage(spec))
// By not setting a JS module name, we force the bundle to be always loaded from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@ public ReactInstanceManager build() {
mApplication,
"Application property has not been set with this builder");

if (mInitialLifecycleState == LifecycleState.RESUMED) {
Assertions.assertNotNull(
mCurrentActivity,
"Activity needs to be set if initial lifecycle state is resumed");
}

Assertions.assertCondition(
mUseDeveloperSupport || mJSBundleAssetUrl != null || mJSBundleLoader != null,
"JS Bundle File or Asset URL has to be provided when dev support is disabled");
Expand Down

0 comments on commit fb550e9

Please sign in to comment.