Skip to content

Commit 1aa6ee3

Browse files
committed
see 05/22 log
1 parent 054846a commit 1aa6ee3

File tree

1 file changed

+12
-44
lines changed

1 file changed

+12
-44
lines changed

app/src/main/java/com/blankj/androidutilcode/feature/core/network/NetworkActivity.java

Lines changed: 12 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
import android.content.Context;
44
import android.content.Intent;
55
import android.os.Bundle;
6-
import android.os.Handler;
7-
import android.os.Message;
86
import android.support.annotation.Nullable;
97
import android.view.View;
108
import android.widget.TextView;
119

1210
import com.blankj.androidutilcode.R;
1311
import com.blankj.androidutilcode.base.BaseBackActivity;
14-
import com.blankj.subutil.util.ThreadPoolUtils;
1512
import com.blankj.utilcode.util.NetworkUtils;
1613
import com.blankj.utilcode.util.SpanUtils;
14+
import com.blankj.utilcode.util.ThreadUtils;
1715

1816
/**
1917
* <pre>
@@ -27,29 +25,18 @@ public class NetworkActivity extends BaseBackActivity {
2725

2826
TextView tvAboutNetwork;
2927
TextView tvAboutNetworkAsync;
30-
ThreadPoolUtils threadPoolUtils = new ThreadPoolUtils(ThreadPoolUtils.SingleThread, 1);
28+
ThreadUtils.SimpleTask mSimpleTask = new ThreadUtils.SimpleTask<String>() {
29+
@Override
30+
public String doInBackground() throws Throwable {
31+
return "isAvailableByPing: " + NetworkUtils.isAvailableByPing()
32+
+ "\ngetDomainAddress: " + NetworkUtils.getDomainAddress("baidu.com");
33+
}
3134

32-
Handler mHandler = new Handler(new Handler.Callback() {
3335
@Override
34-
public boolean handleMessage(Message msg) {
35-
String text = tvAboutNetworkAsync.getText().toString();
36-
if (text.length() != 0) {
37-
text += '\n';
38-
}
39-
if (msg.what == 1) {
40-
tvAboutNetworkAsync.setText(new SpanUtils()
41-
.append(text + "isAvailableByPing: " + msg.obj)
42-
.create()
43-
);
44-
} else {
45-
tvAboutNetworkAsync.setText(new SpanUtils()
46-
.append(text + "getDomainAddress: " + msg.obj)
47-
.create()
48-
);
49-
}
50-
return true;
36+
public void onSuccess(String result) {
37+
tvAboutNetworkAsync.setText(result);
5138
}
52-
});
39+
};
5340

5441
public static void start(Context context) {
5542
Intent starter = new Intent(context, NetworkActivity.class);
@@ -79,25 +66,7 @@ public void initView(Bundle savedInstanceState, View contentView) {
7966

8067
@Override
8168
public void doBusiness() {
82-
threadPoolUtils.execute(new Runnable() {
83-
@Override
84-
public void run() {
85-
Message msg = Message.obtain();
86-
msg.what = 1;
87-
msg.obj = NetworkUtils.isAvailableByPing();
88-
mHandler.sendMessage(msg);
89-
}
90-
});
91-
92-
threadPoolUtils.execute(new Runnable() {
93-
@Override
94-
public void run() {
95-
Message msg = Message.obtain();
96-
msg.what = 2;
97-
msg.obj = NetworkUtils.getDomainAddress("baidu.com");
98-
mHandler.sendMessage(msg);
99-
}
100-
});
69+
ThreadUtils.executeBySingle(mSimpleTask);
10170
}
10271

10372
@Override
@@ -134,8 +103,7 @@ private void updateAboutNetwork() {
134103

135104
@Override
136105
protected void onDestroy() {
137-
threadPoolUtils.shutDownNow();
138-
mHandler.removeCallbacksAndMessages(null);
106+
ThreadUtils.cancel(mSimpleTask);
139107
super.onDestroy();
140108
}
141109
}

0 commit comments

Comments
 (0)