先看我的代码:(用于测试的)
People people1 = new People("join","21");
People people2 = new People("jane","29");
Observable.just(people1,people2)
.subscribeOn(AndroidSchedulers.mainThread()) //在主线程上把 UI 初始化
.doOnNext(people -> {
num = 0;
show.setText(String.valueOf(num));
})
.repeat(4,Schedulers.newThread()) //在新线程上重复发送2次
.observeOn(AndroidSchedulers.mainThread()) //在主线程上观测
.subscribe(peoples1 -> {
String s = people1.toString();
num++;
show.setText(String.valueOf(num));
Log.e("---",s);
});
这里,just先发射第一个 People:people1,之后再发射people2.
但是呢,Logcat如下:
06-29 20:25:20.251 32688-32688/demo.chestnut.com.test E/---: People{name='join', age='21'}
06-29 20:25:20.251 32688-32688/demo.chestnut.com.test E/---: People{name='join', age='21'}
06-29 20:25:20.281 32688-32688/demo.chestnut.com.test E/---: People{name='join', age='21'}
06-29 20:25:20.281 32688-32688/demo.chestnut.com.test E/---: People{name='join', age='21'}
06-29 20:25:20.287 32688-32688/demo.chestnut.com.test E/---: People{name='join', age='21'}
06-29 20:25:20.287 32688-32688/demo.chestnut.com.test E/---: People{name='join', age='21'}
06-29 20:25:20.302 32688-32688/demo.chestnut.com.test E/---: People{name='join', age='21'}
06-29 20:25:20.302 32688-32688/demo.chestnut.com.test E/---: People{name='join', age='21'}
这里打印了8次的 people1,按理由,不是应该打印4次 people1,打印4次的people2吗?
リーリー