From ad89ea7b5046c2cf9ca1cba88c387eb1db8dc042 Mon Sep 17 00:00:00 2001 From: Alexander Komissarov Date: Fri, 17 Nov 2017 11:17:10 -0800 Subject: [PATCH] check if listener is still in the set before calling onHostResume Reviewed By: achen1 Differential Revision: D6341419 fbshipit-source-id: e49188803bbf3641bad6a9cc8c497d453798bbce --- .../facebook/react/bridge/ReactContext.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactContext.java b/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactContext.java index 85959c84547055..bac4fdf8a885bb 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactContext.java +++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactContext.java @@ -141,16 +141,20 @@ public void addLifecycleEventListener(final LifecycleEventListener listener) { case BEFORE_RESUME: break; case RESUMED: - runOnUiQueueThread(new Runnable() { - @Override - public void run() { - try { - listener.onHostResume(); - } catch (RuntimeException e) { - handleException(e); - } - } - }); + runOnUiQueueThread( + new Runnable() { + @Override + public void run() { + if (!mLifecycleEventListeners.contains(listener)) { + return; + } + try { + listener.onHostResume(); + } catch (RuntimeException e) { + handleException(e); + } + } + }); break; default: throw new RuntimeException("Unhandled lifecycle state.");