我也只是处于简单使用阶段,比如在下载啊读取啊需要异步防阻塞的时候用,例如我的一个小项目的一段:
```
Observable.create(new Observable.OnSubscribe<String>() {
@
Override public void call(Subscriber<? super String> subscriber) {
subscriber.onStart();
subscriber.onNext(ResourceUtils.getString(SplashActivity.this,R.string.loading_data));
DBManager.getInstance().init();
SoundPoolManager.getInstance().init();
GifManager.getInstance().init();
subscriber.onNext(ResourceUtils.getString(SplashActivity.this,R.string.loading_data_success));
subscriber.onCompleted();
}
})
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<String>() {
@
Override public void onCompleted() {
startActivity(new Intent(SplashActivity.this,MainActivity.class));
finish();
}
@
Override public void onError(Throwable e) {
mTextView.setText(ResourceUtils.getString(SplashActivity.this,R.string.loading_data_error));
}
@
Override public void onNext(String s) {
mTextView.setText(s);
}
});
```