一、skip语法
public Observable getRxJavaCreateExampleData() {
return Observable.create(new ObservableOnSubscribe() {
@Override
public void subscribe(ObservableEmitter emitter) {
LogUtils.debug(TAG, "getRxJavaCreateExampleData---:" + Thread.currentThread().getName() + "--:" + 1);
emitter.onNext(1);
LogUtils.debug(TAG, "getRxJavaCreateExampleData---:" + Thread.currentThread().getName() + "--:" + 2);
emitter.onNext(2);
LogUtils.debug(TAG, "getRxJavaCreateExampleData---:" + Thread.currentThread().getName() + "--:" + 3);
emitter.onNext(3);
emitter.onComplete();
LogUtils.debug(TAG, "getRxJavaCreateExampleData---:" + Thread.currentThread().getName() + "--:" + 4);
emitter.onNext(4);
}
});
}
public void rxJavaSkipExample() {
Disposable disposable = model.getRxJavaCreateExampleData()
.subscribeOn(Schedulers.io())
.unsubscribeOn(Schedulers.io())
.skip(2)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer() {
@Override
public void accept(Integer integer) throws Exception {
LogUtils.error(TAG, "rxJavaSkipExample--:" + Thread.currentThread().getName() + "-Consumer-:" + integer);
}
});
compositeDisposable.add(disposable);
}
日志
08-18 14:04:40.560 21252-21744/com.example.zhang D/MainModel: getRxJavaCreateExampleData---:RxCachedThreadScheduler-1--:1
getRxJavaCreateExampleData---:RxCachedThreadScheduler-1--:2
getRxJavaCreateExampleData---:RxCachedThreadScheduler-1--:3
getRxJavaCreateExampleData---:RxCachedThreadScheduler-1--:4
08-18 14:04:40.564 21252-21252/com.example.zhang E/MainPresenter: rxJavaSkipExample--:main-Consumer-:3
总结
1、skip(long count) count 跳过count个