一、添加依赖

     compile 'io.reactivex:rxandroid:1.2.0'
compile 'io.reactivex:rxjava:1.1.5'
compile 'com.google.code.gson:gson:2.4'
compile 'com.squareup.retrofit2:retrofit:2.0.2'
compile 'com.squareup.retrofit2:converter-gson:2.0.2'
compile 'com.squareup.retrofit2:converter-jackson:2.0.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2'
compile 'com.squareup.okhttp3:okhttp:3.0.1'
compile 'com.squareup.okhttp3:logging-interceptor:3.0.1'
compile 'com.squareup.okio:okio:1.6.0'

二、添加依赖可能出现的错误以及解决

Error:Execution failed for task':retrofitdemo:transformResourcesWithMergeJava

解决方法:

android {
compileSdkVersion 24
buildToolsVersion "24.0.2" packagingOptions {
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/notice'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license'
exclude 'META-INF/license.txt'
}
}

三、操作:

(1)延时操作

 private void timerOption() {
Observable.timer(3000, TimeUnit.MILLISECONDS)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<Long>() {
@Override
public void call(Long aLong) {
startActivity(new Intent(SplashActivity.this, NewsActivity.class));
overridePendingTransition(0, android.R.anim.fade_out);
finish();
}
});
}

(2)具体使用:

给 Android 开发者的 RxJava 详解

05-08 15:01