Skip to content

Commit fc35a65

Browse files
javachefacebook-github-bot
authored andcommitted
moveToResumedLifecycleState must be called from UI thread
Summary: I was seeing a SoftException in our apps due to this method being called as part of ReactInstanceManager's init. It seems inconsistent that we would call this from a background thread when all other `onHost*` methods are marked as confined to the UI thread. Changelog: [Internal] Reviewed By: ryancat Differential Revision: D34340210 fbshipit-source-id: 0104eda66b2ca6bb315e64e806e9a30409d0d45c
1 parent bb7214b commit fc35a65

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,6 @@ private void setupReactContext(final ReactApplicationContext reactContext) {
11751175

11761176
mDevSupportManager.onNewReactContextCreated(reactContext);
11771177
mMemoryPressureRouter.addMemoryPressureListener(catalystInstance);
1178-
moveReactContextToCurrentLifecycleState();
11791178

11801179
ReactMarker.logMarker(ATTACH_MEASURED_ROOT_VIEWS_START);
11811180
for (ReactRoot reactRoot : mAttachedReactRoots) {
@@ -1197,6 +1196,8 @@ private void setupReactContext(final ReactApplicationContext reactContext) {
11971196
new Runnable() {
11981197
@Override
11991198
public void run() {
1199+
moveReactContextToCurrentLifecycleState();
1200+
12001201
for (com.facebook.react.ReactInstanceEventListener listener : finalListeners) {
12011202
// Sometimes this listener is null - probably due to race
12021203
// condition between allocating listeners with a certain
@@ -1208,10 +1209,6 @@ public void run() {
12081209
}
12091210
}
12101211
});
1211-
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
1212-
ReactMarker.logMarker(SETUP_REACT_CONTEXT_END);
1213-
// Mark end of bridge loading
1214-
ReactMarker.logMarker(ReactMarkerConstants.REACT_BRIDGE_LOADING_END);
12151212
reactContext.runOnJSQueueThread(
12161213
new Runnable() {
12171214
@Override
@@ -1227,6 +1224,11 @@ public void run() {
12271224
Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
12281225
}
12291226
});
1227+
1228+
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
1229+
ReactMarker.logMarker(SETUP_REACT_CONTEXT_END);
1230+
// Mark end of bridge loading
1231+
ReactMarker.logMarker(ReactMarkerConstants.REACT_BRIDGE_LOADING_END);
12301232
}
12311233

12321234
private void attachRootViewToInstance(final ReactRoot reactRoot) {

ReactAndroid/src/main/java/com/facebook/react/bridge/ReactContext.java

+2
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ public void removeWindowFocusChangeListener(WindowFocusChangeListener listener)
254254
}
255255

256256
/** Should be called by the hosting Fragment in {@link Fragment#onResume} */
257+
@ThreadConfined(UI)
257258
public void onHostResume(@Nullable Activity activity) {
258259
mLifecycleState = LifecycleState.RESUMED;
259260
mCurrentActivity = new WeakReference(activity);
@@ -282,6 +283,7 @@ public void onNewIntent(@Nullable Activity activity, Intent intent) {
282283
}
283284

284285
/** Should be called by the hosting Fragment in {@link Fragment#onPause} */
286+
@ThreadConfined(UI)
285287
public void onHostPause() {
286288
mLifecycleState = LifecycleState.BEFORE_RESUME;
287289
ReactMarker.logMarker(ReactMarkerConstants.ON_HOST_PAUSE_START);

0 commit comments

Comments
 (0)