Android使用rxjava
导入包
implementation "io.reactivex.rxjava2:rxjava:2.2.10"
implementation "io.reactivex.rxjava2:rxandroid:2.0.2"
使用
private void executeAsyncTask() { //Observable#create方法创建一个异步任务 Observable.create(new ObservableOnSubscribe<Integer>() { @Override public void subscribe(@NonNull ObservableEmitter<Integer> e) throws Exception { e.onComplete(); } }) .subscribe(new Observer<Integer>() { @Override public void onSubscribe(@NonNull Disposable d) { } @Override public void onNext(@NonNull Integer integer) { } @Override public void onError(@NonNull Throwable e) { } @Override public void onComplete() { } }); }