TShopping

 找回密碼
 註冊
搜索
查看: 1632|回復: 0
打印 上一主題 下一主題

[教學] RootShell 如何等command做完再執行(waitFor)

[複製鏈接]
跳轉到指定樓層
1#
發表於 2018-3-23 00:45:54 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
 
Push to Facebook
  1. Command cmd = new Command(158, false, pathstring);
  2.             Shell shell = Shell.startRootShell(158,158);
  3.             shell.add(cmd);
  4.             waitForCommand(cmd);
複製代碼
Command cmd = new Command(158, false, pathstring);
handleEnable = false
這樣Thread才不會咬住

158只是int 整數,隨便填


一定要
Shell shell = Shell.startRootShell(158,158);
shell.add(cmd);

後,再執行 cmd

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

  1. private static boolean waitForCommand(Command cmd) {
  2.         while (!cmd.isFinished()) {
  3.             synchronized (cmd) {
  4.                 try {
  5.                     if (!cmd.isFinished()) {
  6.                         cmd.wait(1);
  7.                     }
  8.                 } catch (InterruptedException e) {
  9.                     e.printStackTrace();
  10.                 }
  11.             }
  12.             if (!cmd.isExecuting() && !cmd.isFinished()) {
  13.                 Log.d("Debug", "Error: not complete");
  14.                 return false;
  15.             }
  16.         }
  17.         return true;
  18.     }
複製代碼

參考文章
https://blog.csdn.net/andrexpert/article/details/53082397
https://www.programcreek.com/jav ... ell.execution.Shell
https://github.com/Stericson/Roo ... hell/RootShell.java




 

臉書網友討論
*滑块验证:
您需要登錄後才可以回帖 登錄 | 註冊 |

本版積分規則



Archiver|手機版|小黑屋|免責聲明|TShopping

GMT+8, 2024-4-27 22:32 , Processed in 0.055338 second(s), 22 queries .

本論壇言論純屬發表者個人意見,與 TShopping綜合論壇 立場無關 如有意見侵犯了您的權益 請寫信聯絡我們。

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表