rxjava2.Xhttps://github.com/ReactiveX/RxJava/tree/2.x
1.rxbinding
compile 'com.jakewharton.rxbinding:rxbinding:1.0.0'//还不支持rxjava2.0同时导入会导致rxjava报以下类似错误
- // com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/rxjava.properties
- // File1: C:\Users\Administrator\.gradle\caches\modules-2\files-2.1\io.reactivex\rxjava\1.1.5\ece7b5d0870e66d8226dab6dcf47a2b12afff061\rxjava-1.2.3.jar
- // File2: C:\Users\Administrator\.gradle\caches\modules-2\files-2.1\io.reactivex.rxjava2\rxjava\2.0.1\57f850a6b317e5582f1dbaff10a9e7d7e1fcdcfb\rxjava-2.0.1.jar
以下Rxbingding转载:http://blog.csdn.net/zy157953/article/details/51729222
Rxbingding最好的运用场景在与定时操作、循环操作。还有不能重复点击。
Button button=(Button)findViewById(R.id.bt_button);
//判断短时间内不能重复点击
RxView.clicks(button).debounce(300, TimeUnit.MILLISECONDS).subscribe(new Action1<Void>() {
@Override
public void call(Void aVoid) {
Intent intent =new Intent(MainActivity.this,SecondActivity.class);
startActivity(intent);
finish();
}
});
//轮询操作,每两秒执行一次
Observable.interval(2,2,TimeUnit.SECONDS).subscribe(new Action1<Long>() {
@Override
public void call(Long aLong) {
//TODO EVERTHING YOU WANT
}
});
//定时操作,两秒后执行
Observable.timer(2, TimeUnit.SECONDS).subscribe(new Action1<Long>() {
@Override
public void call(Long aLong) {
//TODO WHAT YOU WANT
RxBus.getInstance().post("我喜欢你");
}
});
2.RxSmartSharedPreferences
RxSmartSharedPreferences是SmartSharedPreferences的Rx版,增加了2个Rx相关的方法。
RxSmartSharedPreferences可以让你创建实体类一样创建一个SharedPreferences对象,使用链式方法操作数据.
链式操作感觉没有多大吸引力,只适用对象的概念存取的封装方法还是不错的然后对于静态的key比较实用,对于那种动态的循环存取不大试用.
github位置: https://github.com/YoKeyword/RxSmartSharedPreferences3.rxlifecycle
导包:
compile 'com.trello:rxlifecycle:1.0'异常???
// If you want pre-written Activities and Fragments you can subclass as providers
compile 'com.trello:rxlifecycle-components:1.0'
Warning:Conflict with dependency 'com.google.code.findbugs:jsr305'. Resolved versions for app (3.0.1) and test app (2.0.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
解决办法:(转:http://blog.csdn.net/qq_23089525/article/details/52777520)
在您的应用程序build.gradle添加内的下列Android { }:
configurations.all {然后,很不幸的和rxbindinfg一样,还不兼容rxjava2.0
resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}