Hello, I have a question on the use of Schedulers in the process, the operation of the UI in Android development, should be the main thread of execution, why I use the observeOn (Schedulers.io ()), TextView can still assignment, which is how to do, please help me to answer, very grateful.Code is as follows:
myTextView.setText("thread 1 id=" + Thread.currentThread().getId());
Observable.just(1, 2, 3, 4)
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.newThread())
.map(new Func1<Integer, String>() {
@Override
public String call(Integer integer) {
myTextView.setText(myTextView.getText() + "\n" + "thread 2 id =" +
Thread.currentThread().getId());
return "5" + integer;
}
})
.observeOn(Schedulers.io())
.map(new Func1<String, Integer>() {
@Override
public Integer call(String s) {
myTextView.setText(myTextView.getText() + "\n" + "thread 3 id =" +
Thread.currentThread().getId());
return Integer.parseInt(s);
}
});
Results : TextView normal display
Hello, I have a question on the use of Schedulers in the process, the operation of the UI in Android development, should be the main thread of execution, why I use the observeOn (Schedulers.io ()), TextView can still assignment, which is how to do, please help me to answer, very grateful.Code is as follows:
Results : TextView normal display