Skip to content

Commit 215da13

Browse files
committed
优化示例
1 parent 17ca809 commit 215da13

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

sample/src/main/java/com/excellence/exec/sample/MainActivity.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

sample/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
android:id="@+id/button"
1212
android:layout_width="wrap_content"
1313
android:layout_height="wrap_content"
14-
android:text="测试命令:ls"
14+
android:text="测试命令:top"
1515
android:textAllCaps="false"/>
1616

1717
<ScrollView

0 commit comments

Comments
 (0)