mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-21 02:26:18 +08:00
check lifecycle event is coming from current activity
Summary: If a paused activity is destroyed (e.g. because of resource contention), we send onHostDestroyed to all modules even if there's an on-screen, resumed activity using the current react instance. This diff adds a check to make sure lifecycle events come from the current activity, and ignores ones that don't. Reviewed By: astreet Differential Revision: D3655422 fbshipit-source-id: 0f95fda124df3732447853b9bc34c40836a4b1da
This commit is contained in:
committed by
Facebook Github Bot 1
parent
46dc46a3b3
commit
0b5c61250b
@@ -489,6 +489,17 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
||||
moveToBeforeResumeLifecycleState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHostPause(Activity activity) {
|
||||
Assertions.assertNotNull(mCurrentActivity);
|
||||
Assertions.assertCondition(
|
||||
activity == mCurrentActivity,
|
||||
"Pausing an activity that is not the current activity, this is incorrect! " +
|
||||
"Current activity: " + mCurrentActivity.getClass().getSimpleName() + " " +
|
||||
"Paused activity: " + activity.getClass().getSimpleName());
|
||||
onHostPause();
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method when the activity resumes to enable invoking the back button directly from JS.
|
||||
*
|
||||
@@ -525,6 +536,13 @@ import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
||||
mCurrentActivity = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHostDestroy(Activity activity) {
|
||||
if (activity == mCurrentActivity) {
|
||||
onHostDestroy();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
UiThreadUtil.assertOnUiThread();
|
||||
|
||||
Reference in New Issue
Block a user