찾다

 >  Q&A  >  본문

android - Rxjava 的 Repeat 操作符

先看我的代码:(用于测试的)

        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吗?

PHPzPHPz2771일 전715

모든 응답(1)나는 대답할 것이다

  • 伊谢尔伦

    伊谢尔伦2017-04-17 17:23:24

    으아아아

    회신하다
    0
  • 취소회신하다