一:RxAndroid的发展
RxJava针对Android平台的扩展,方便RxJava用于Android开发
二:RxAndroid有什么功能
AndroidObservable
ViewObservable
bindActivity()
fromBroadcast()
三:RxAndroid的更新
rxandroid:0.25.0 —rxandroid:1.2.1
LifecycleObservable RxLifecycle框架
fromSharedPreferencesChanges() RxPreferences框架
WidgetObservable , ViewObservable RxBinding框架
AppObservable类及其方法移除
AndroidSchedulers.mainThread()保留
四:举个栗子 :模拟在io线程加载数据 在主线程显示
private void testRxJava9(){
final StringBuffer buffer = new StringBuffer();
// rx.Observable.just("one","two","three")
initObservable()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<String>() {
@Override
public void call(String s) {
buffer.append(s);
Log.d(TAG,"item:"+s);
mTextView.setText(buffer.toString());
}
});
}
private rx.Observable<String> initObservable(){
return rx.Observable.defer(new Func0<rx.Observable<String>>() {
@Override
public rx.Observable<String> call() {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return rx.Observable.just("one","two","three");
}
});
}