private void postCallback(final Command fCommand, final int fExitCode, final List<String> fOutput) {
      if (fCommand.onCommandResultListener == null && fCommand.onCommandLineListener == null) {
        return;
      }
      if (handler == null/* || !handler.getLooper().getThread().isAlive()*/) {
        if ((fCommand.onCommandResultListener != null) && (fOutput != null))
          fCommand.onCommandResultListener.onCommandResult(fCommand.code, fExitCode, fOutput);
        if (fCommand.onCommandLineListener != null)
          fCommand.onCommandLineListener.onCommandResult(fCommand.code, fExitCode);
        return;
      }
      startCallback();

      handler.post(new Runnable() {

        @Override
        public void run() {
          try {
            if ((fCommand.onCommandResultListener != null) && (fOutput != null))
              fCommand.onCommandResultListener.onCommandResult(fCommand.code, fExitCode, fOutput);
            if (fCommand.onCommandLineListener != null)
              fCommand.onCommandLineListener.onCommandResult(fCommand.code, fExitCode);
          } finally {
            endCallback();
          }
        }
      });
    }
Schedule a callback to run on the appropriate thread
imitate/src/main/java/com/engineer/imitate/shell/Shell.java