@Override
  public void finish() {
    super.finish();

    if (shouldFinishRootActivity()) {
      TiApplication app = getTiApp();
      if (app != null) {
        TiRootActivity rootActivity = app.getRootActivity();
        if (rootActivity != null && !(rootActivity.equals(this)) && !rootActivity.isFinishing()) {
          rootActivity.finish();
        } else if (rootActivity == null && !app.isRestartPending()) {
          // When the root activity has been killed and garbage collected and the app is not
          // scheduled to restart,
          // we need to force finish the root activity while this activity has an intent to finish
          // root.
          // This happens when the "Don't keep activities" option is enabled and the user stays in
          // some activity
          // (eg. heavyweight window, tabgroup) other than the root activity for a while and then he
          // wants to back
          // out the app.
          app.setForceFinishRootActivity(true);
        }
      }
    }
  }
  @Override
  public void finish() {
    TiDict data = new TiDict();
    for (WeakReference<TiContext> contextRef : contexts) {
      if (contextRef.get() != null) {
        contextRef.get().dispatchEvent("close", data, proxy);
      }
    }

    if (createdContext != null && createdContext.get() != null) {
      createdContext.get().dispatchEvent("close", data, proxy);
    }

    boolean animate = true;
    Intent intent = getIntent();

    if (intent != null) {
      if (intent.getBooleanExtra("finishRoot", false)) {
        if (getApplication() != null) {
          TiApplication tiApp = getTiApp();
          if (tiApp != null) {
            TiRootActivity rootActivity = tiApp.getRootActivity();
            if (rootActivity != null) {
              rootActivity.finish();
            }
          }
        }
      }
      animate = intent.getBooleanExtra("animate", animate);
    }

    super.finish();
    if (!animate) {
      TiUIHelper.overridePendingTransition(this);
    }
  }