I have implemented a timer using RxJava.
rx.Subscription subscription = rx.Observable.interval(1000, 1000, TimeUnit.MILLISECONDS)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()).distinct()
.cache().doOnNext(new Action1<Long>() {
@Override
public void call(Long aLong) {
timer.setText(String.valueOf(aLong)); )
.subscribe();
I'd like to know :
1) How do I pause this timer? I used subscription.unsubscribe(); and it paused, but I do not know if it's a good idea.
2) How could I resume the timer? Let's say I paused it, so how could I continue the timer from where it has stopped?