-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Guo Yang
authored
Feb 7, 2017
1 parent
42d0dd4
commit 4d367df
Showing
1 changed file
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
}); |