Reputation: 936
so i have this method below which starts a timer when i click a button 'B' after 59 seconds the timerview's invisibility is set as gone, the code is working fine except, when i click on button 'B' again to start the whole process once more, nothing happens! why is that?
@Override
public void timerStart() {
getCompositeDisposable()
.add(Observable.interval(0, 1000, TimeUnit.MILLISECONDS)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<Long>() {
@Override
public void accept(Long aLong) throws Exception {
if (time > 0) {
String timer = String.format("%s:%s", "00", time <= 9 ? "0" + time : String.valueOf(time));
getMvpView().updateTimer(timer);
time--;
} else {
getMvpView().hideTimer();
}
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
getMvpView().hideTimer();
}
}
)
);
}
Upvotes: 0
Views: 119
Reputation: 1687
I think it's because of variable time. Maybe it can't be positive again after the first call of timestart(). (your portion of code does not show which other function can update time or where is the initialisation)
Upvotes: 1