private void tearDownReactContext(ReactContext reactContext) {
   UiThreadUtil.assertOnUiThread();
   if (mLifecycleState == LifecycleState.RESUMED) {
     reactContext.onHostPause();
   }
   for (ReactRootView rootView : mAttachedRootViews) {
     detachViewFromInstance(rootView, reactContext.getCatalystInstance());
   }
   reactContext.destroy();
   mDevSupportManager.onReactInstanceDestroyed(reactContext);
   mMemoryPressureRouter.removeMemoryPressureListener(reactContext.getCatalystInstance());
 }
 /**
  * Detach given {@param rootView} from current catalyst instance. It's safe to call this method
  * multiple times on the same {@param rootView} - in that case view will be detached with the
  * first call.
  */
 @Override
 public void detachRootView(ReactRootView rootView) {
   UiThreadUtil.assertOnUiThread();
   if (mAttachedRootViews.remove(rootView)) {
     if (mCurrentReactContext != null && mCurrentReactContext.hasActiveCatalystInstance()) {
       detachViewFromInstance(rootView, mCurrentReactContext.getCatalystInstance());
     }
   }
 }
  /**
   * Attach given {@param rootView} to a catalyst instance manager and start JS application using JS
   * module provided by {@link ReactRootView#getJSModuleName}. If the react context is currently
   * being (re)-created, or if react context has not been created yet, the JS application associated
   * with the provided root view will be started asynchronously, i.e this method won't block. This
   * view will then be tracked by this manager and in case of catalyst instance restart it will be
   * re-attached.
   */
  @Override
  public void attachMeasuredRootView(ReactRootView rootView) {
    UiThreadUtil.assertOnUiThread();
    mAttachedRootViews.add(rootView);

    // If react context is being created in the background, JS application will be started
    // automatically when creation completes, as root view is part of the attached root view list.
    if (mReactContextInitAsyncTask == null && mCurrentReactContext != null) {
      attachMeasuredRootViewToInstance(rootView, mCurrentReactContext.getCatalystInstance());
    }
  }