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:
Felix Oghina
2016-08-08 09:01:16 -07:00
committed by Facebook Github Bot 1
parent 46dc46a3b3
commit 0b5c61250b
3 changed files with 66 additions and 5 deletions

View File

@@ -97,8 +97,22 @@ public abstract class ReactInstanceManager {
/**
* Call this from {@link Activity#onPause()}. This notifies any listening modules so they can do
* any necessary cleanup.
*
* @deprecated Use {@link #onHostPause(Activity)} instead.
*/
@Deprecated
public abstract void onHostPause();
/**
* Call this from {@link Activity#onPause()}. This notifies any listening modules so they can do
* any necessary cleanup. The passed Activity is the current Activity being paused. This will
* always be the foreground activity that would be returned by
* {@link ReactContext#getCurrentActivity()}.
*
* @param activity the activity being paused
*/
public abstract void onHostPause(Activity activity);
/**
* Use this method when the activity resumes to enable invoking the back button directly from JS.
*
@@ -117,8 +131,21 @@ public abstract class ReactInstanceManager {
/**
* Call this from {@link Activity#onDestroy()}. This notifies any listening modules so they can do
* any necessary cleanup.
*
* @deprecated use {@link #onHostDestroy(Activity)} instead
*/
@Deprecated
public abstract void onHostDestroy();
/**
* Call this from {@link Activity#onDestroy()}. This notifies any listening modules so they can do
* any necessary cleanup. If the activity being destroyed is not the current activity, no modules
* are notified.
*
* @param activity the activity being destroyed
*/
public abstract void onHostDestroy(Activity activity);
public abstract void onActivityResult(int requestCode, int resultCode, Intent data);
public abstract void showDevOptionsDialog();