@@ -18,6 +18,7 @@ public class MainActivity extends AppCompatActivity implements IListener {
1818
1919 private Button mButton = null ;
2020 private TextView mTextView = null ;
21+ private CommandTask mTask = null ;
2122
2223 @ Override
2324 protected void onCreate (Bundle savedInstanceState ) {
@@ -27,26 +28,26 @@ protected void onCreate(Bundle savedInstanceState) {
2728 mButton = (Button ) findViewById (R .id .button );
2829 mTextView = (TextView ) findViewById (R .id .text );
2930
31+ /**
32+ * 默认10s超时
33+ */
34+ Commander .init (new CommanderOptions .Builder ().timeOut (10000 ).build ());
35+
3036 mButton .setOnClickListener (new View .OnClickListener () {
3137 @ Override
3238 public void onClick (View v ) {
33- Commander .init (new CommanderOptions .Builder ().timeOut (10000 ).build ());
3439 mTextView .setText ("" );
40+ if (mTask != null ) {
41+ mTask .discard ();
42+ mTask = null ;
43+ return ;
44+ }
3545 /**
36- * 5s超时
46+ * 0s延时
3747 */
38- final CommandTask task = new CommandTask .Builder ().command ("ls " ).timeDelay (5000 ).build ();
39- task .deploy (MainActivity .this );
48+ mTask = new CommandTask .Builder ().command ("top " ).timeDelay (0 ).build ();
49+ mTask .deploy (MainActivity .this );
4050 // final CommandTask task = Commander.addTask("ls", MainActivity.this);
41- mButton .postDelayed (new Runnable () {
42- @ Override
43- public void run () {
44- /**
45- * 延时8s取消任务
46- */
47- task .discard ();
48- }
49- }, 8000 );
5051 }
5152 });
5253
@@ -60,7 +61,7 @@ public void onPre(String command) {
6061
6162 @ Override
6263 public void onProgress (String message ) {
63- //Log.i(TAG, "onProgress: " + message);
64+ // Log.i(TAG, "onProgress: " + message);
6465 mTextView .append (message + "\n " );
6566 }
6667
0 commit comments