/**
   * Tear down the session after rendering.
   *
   * <p>The counterpart is {@link #setUp()}.
   */
  private void tearDown() {
    // The context may be null, if there was an error during init().
    if (mContext != null) {
      // Make sure to remove static references, otherwise we could not unload the lib
      mContext.disposeResources();
    }

    if (sCurrentContext != null) {
      // quit HandlerThread created during this session.
      HandlerThread_Delegate.cleanUp(sCurrentContext);
    }

    // clear the stored ViewConfiguration since the map is per density and not per context.
    ViewConfiguration_Accessor.clearConfigurations();

    // remove the InputMethodManager
    InputMethodManager_Accessor.resetInstance();

    sCurrentContext = null;

    Bridge.setLog(null);
    if (mContext != null) {
      mContext.getRenderResources().setFrameworkResourceIdProvider(null);
      mContext.getRenderResources().setLogger(null);
    }
    ParserFactory.setParserFactory(null);
  }
  /**
   * Sets up the session for rendering.
   *
   * <p>The counterpart is {@link #tearDown()}.
   */
  private void setUp() {
    // make sure the Resources object references the context (and other objects) for this
    // scene
    mContext.initResources();
    sCurrentContext = mContext;

    // create an InputMethodManager
    InputMethodManager.getInstance();

    LayoutLog currentLog = mParams.getLog();
    Bridge.setLog(currentLog);
    mContext.getRenderResources().setFrameworkResourceIdProvider(this);
    mContext.getRenderResources().setLogger(currentLog);
  }