Skip to content

Commit ff9855c

Browse files
RoJoHubkelset
authored andcommittedJul 3, 2019
Check if mCurrentActivity is set according to LifecycleState (#23336)
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
1 parent 8a43321 commit ff9855c

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed
 

‎ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactAppTestActivity.java

+8
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,14 @@ public void loadBundle(final ReactInstanceSpecForTest spec, String bundleName, b
213213
} else {
214214
builder.addPackage(new MainReactPackage());
215215
}
216+
/**
217+
* The {@link ReactContext#mCurrentActivity} never to be set if initial lifecycle state is resumed.
218+
* So we should call {@link ReactInstanceManagerBuilder#setCurrentActivity}.
219+
*
220+
* Finally,{@link ReactInstanceManagerBuilder#build()} will create instance of {@link ReactInstanceManager}.
221+
* And also will set {@link ReactContext#mCurrentActivity}.
222+
*/
223+
builder.setCurrentActivity(this);
216224
builder
217225
.addPackage(new InstanceSpecForTestPackage(spec))
218226
// By not setting a JS module name, we force the bundle to be always loaded from

‎ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManagerBuilder.java

+6
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,12 @@ public ReactInstanceManager build() {
246246
mApplication,
247247
"Application property has not been set with this builder");
248248

249+
if (mInitialLifecycleState == LifecycleState.RESUMED) {
250+
Assertions.assertNotNull(
251+
mCurrentActivity,
252+
"Activity needs to be set if initial lifecycle state is resumed");
253+
}
254+
249255
Assertions.assertCondition(
250256
mUseDeveloperSupport || mJSBundleAssetUrl != null || mJSBundleLoader != null,
251257
"JS Bundle File or Asset URL has to be provided when dev support is disabled");

0 commit comments

Comments
 (0)
Please sign in to comment.