RxJava - emits observable every second

I am making a timer in Android using RxJava. I need to make a timer in RxJava to emit observables every second. I tried the following but no luck. Any thoughts on what I'm doing wrong?

Observable.interval(1000L, TimeUnit.MILLISECONDS)
          .timeInterval()
          .observeOn(AndroidSchedulers.mainThread())
          .subscribe({Log.d(LOG_TAG, "&&&& on timer") })
+4
source share
2 answers

Your code does not seem to be called. Check if this is done and when. As for working with Observable, this is completely correct.

For example, I put your fragment inside onCreate(...)mine MainActivity:

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    Observable.interval(1000L, TimeUnit.MILLISECONDS)
            .timeInterval()
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe { Log.d("tag", "&&&& on timer") }
    // ...
}

And it works:

https://www.dropbox.com/s/jxkm5ol8l5idyji/observable_interval.png?dl= 0

, , .timeInterval(), Observable.interval(...) , .timeInterval() , , .

+13

subscribe() longTimeInterval, timeInterval().

:

.subscribe(longTimeInterval -> {
     Log.d(LOG_TAG, "&&&& on timer"); 
}

, timeInterval(). Observable.interval() , , , . timeInterval() , , , .

0

All Articles