0

I use the following code to realize the countdown display at the millisecond level. After onSubscribe is executed, the onNext method is executed nearly one minute later.

This problem occurs occasionally. This problem also exists when creating Observable using the create method.

I don't have any solutions at present. Please help me, thank you

Observable.interval(1900, 50, TimeUnit.MILLISECONDS).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnDispose(() -> {
                    XLog.i("doOnDispose");
                })
                .compose(RxUtils.bindToLifecycle(provider))
                .subscribe(new Observer<Long>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {
                        XLog.i("onSubscribe");
                    }

                    @Override
                    public void onNext(@NonNull Long aLong) {
                        XLog.i("onNext");
                        // refresh ui countdown
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        XLog.i("onError");
                    }

                    @Override
                    public void onComplete() {
                        XLog.i("onComplete");
                    }
                });

I don't have any solutions at present

Jin
  • 31
  • 2
  • Can you check if the problem also occurs when skipping part related to lifecycle binding? compose(RxUtils.bindToLifecycle(provider)) – bongo Jan 31 '23 at 09:10
  • @bongo The same problem exists without using lifecycle binding code – Jin Jan 31 '23 at 10:04
  • Can also try two other options - use subscribeOn with Schedulers.computation() instead of Schedulers.io() - increase delay from 50 to for example 200ms – bongo Jan 31 '23 at 10:12
  • Maybe the logging system suppresses chatty or duplicate log messages? Also please try `Observable.interval(1900, 50, TimeUnit.MILLISECONDS, AndroidSchedulers.mainThread())` as there should be no need apply `subscribeOn` and `observeOn` operators. – akarnokd Jan 31 '23 at 13:35
  • @bongo I will try to replace Schedulers. io() with Schedulers. computation(). The time interval setting may not be the cause of this problem, because I also have this problem when I use the create method to create Observable. Thank you for your answer~ – Jin Feb 01 '23 at 01:24

0 Answers0