一、RxJava-timer语法
public void rxJavaTimeExample() {
LogUtils.error(TAG, "rxJavaTimeExample--start--:" + Thread.currentThread().getName() + "--:" + TimeUtils.getNowString());
Disposable disposable = Observable.timer(4, TimeUnit.SECONDS)
.subscribeOn(Schedulers.io())
.unsubscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<Long>() {
@Override
public void accept(Long aLong) throws Exception {
LogUtils.error(TAG, "rxJavaTimeExample--end--:" + Thread.currentThread().getName() + "--:" +TimeUtils.getNowString()+"---long:"+aLong);
}
});
compositeDisposable.add(disposable);
}
日志
08-18 10:28:55.678 4505-4505/com.example.zhang E/MainPresenter: rxJavaTimeExample--start--:main--:2018-08-18 10:28:55
08-18 10:28:59.852 4505-4505/com.example.zhang E/MainPresenter: rxJavaTimeExample--end--:main--:2018-08-18 10:28:59---long:0
总结
1、timer(long delay, TimeUnit unit) delay 延迟时间 unit 时间单位
2、timer属于类方法 ,delay属于对象方法