//倒计时10-1
Observable.interval(1, TimeUnit.SECONDS)
.take(10) // up to 10 items
.map(new Function() {
@Override
public Long apply(Long v) throws Exception {
return 10 - v;
}
})
.subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer() {
@Override
public void onSubscribe(@NonNull Disposable d) {
// on start
}
@Override
public void onNext(@NonNull Long aLong) {
Log.i(TAG, "count down : aLong=" + aLong);
}
@Override
public void onError(@NonNull Throwable e) {
}
@Override
public void onComplete() {
Log.i(TAG, "----------倒计时结束------------");
}
});