RxJAVA notes
注: 本文只适用于自我复习,初学者请移步 链接
常用模板
rxjava2+retrofit2
public static void main(String[] args) { String BASE_URL = " http://www.izaodao.com/Api/"; okhttp3.OkHttpClient.Builder builder = new OkHttpClient.Builder(); builder.connectTimeout(5, TimeUnit.SECONDS); Retrofit retrofit = new Retrofit.Builder() .client(builder.build()) .addConverterFactory(GsonConverterFactory.create()) .baseUrl(BASE_URL) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .build(); MyApiEndpointInterface apiService = retrofit.create(MyApiEndpointInterface.class); Observable<RetrofitEntity> observable = apiService.getAllVedioBy(true); observable.subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new DisposableObserver<RetrofitEntity>() { @Override public void onComplete() { } @Override public void onError(Throwable e) { } @Override public void onNext(RetrofitEntity retrofitEntity) { System.out.println(retrofitEntity.toString()); } }); }
mvp+rxjava: 链接
Retrofit2 源码分析:链接
Okhttp3 源码分析:链接
rxjava操作符大全:链接
empty:创建一个不发射任何数据但是正常终止的Observable
never:创建一个不发射数据也不终止的Observable
error:创建一个不发射数据以一个错误终止的Observable
一起造一个rxjava:链接