woff 發表於 2018-3-23 00:45:54

RootShell 如何等command做完再執行(waitFor)

Command cmd = new Command(158, false, pathstring);
            Shell shell = Shell.startRootShell(158,158);
            shell.add(cmd);
            waitForCommand(cmd);Command cmd = new Command(158, false, pathstring);
handleEnable = false
這樣Thread才不會咬住

158只是int 整數,隨便填


一定要
Shell shell = Shell.startRootShell(158,158);
shell.add(cmd);
後,再執行 cmd

不要用範例的
Command cmd = new Command(pathstring);
Shell.startRootShell().add(command);操作會變得很慢然後建waitForCommand function

private static boolean waitForCommand(Command cmd) {
      while (!cmd.isFinished()) {
            synchronized (cmd) {
                try {
                  if (!cmd.isFinished()) {
                        cmd.wait(1);
                  }
                } catch (InterruptedException e) {
                  e.printStackTrace();
                }
            }
            if (!cmd.isExecuting() && !cmd.isFinished()) {
                Log.d("Debug", "Error: not complete");
                return false;
            }
      }
      return true;
    }
參考文章
https://blog.csdn.net/andrexpert/article/details/53082397
https://www.programcreek.com/jav ... ell.execution.Shell
https://github.com/Stericson/Roo ... hell/RootShell.java



頁: [1]
查看完整版本: RootShell 如何等command做完再執行(waitFor)