Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Guo Yang authored Feb 7, 2017
1 parent 42d0dd4 commit 4d367df
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,51 @@
#RxUtilDemo
//使用内部封装的线程池进行耗时任务Toast.makeText(this, "IO线程进行耗时操作,请在控制台查看Log", Toast.LENGTH_SHORT).show();String str = "模拟IO线程执行耗时操作";RxjavaUtil.doInIOThread(new IOTask<String>(str) { @Override public void doInIOThread() { for (int i = 0; i < 5; i++) { try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } Log.v("test", getT()); } }});
//使用内部封装的线程池进行耗时任务
Toast.makeText(this, "IO线程进行耗时操作,请在控制台查看Log", Toast.LENGTH_SHORT).show();
String str = "模拟IO线程执行耗时操作";
RxjavaUtil.doInIOThread(new IOTask<String>(str) {
@Override
public void doInIOThread() {
for (int i = 0; i < 5; i++) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Log.v("test", getT());
}
}
});

//在子线程中修改UI
new Thread(new Runnable() {
@Override
public void run() {
String str2 = "子线程中修改UI";
RxjavaUtil.doInUIThread(new UITask<String>(str2) {
@Override
public void doInUIThread() {
tv_test.setText(getT());
}
});
}
}).start();

//在IO线程进行耗时操作 执行完成后修改UI
String str3 = "耗时操作结束修改UI";
Toast.makeText(this, "请等候三秒再看测试的文本框内容变化", Toast.LENGTH_SHORT).show();
RxjavaUtil.executeRxTask(new CommonRxTask<String>(str3) {
@Override
public void doInIOThread() {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
setT(getT() + "--------小尾巴");
}

@Override
public void doInUIThread() {
tv_test.setText(getT());
}
});

0 comments on commit 4d367df

Please sign in to comment.