将AsyncTask转换为RxAndroid [英] Convert AsyncTask to RxAndroid
本文介绍了将AsyncTask转换为RxAndroid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下方法使用otto和AsyncTask
将响应发布到UI.
I have the following method to post response to UI using otto and AsyncTask
.
private static void onGetLatestStoryCollectionSuccess(final StoryCollection storyCollection, final Bus bus) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
bus.post(new LatestStoryCollectionResponse(storyCollection));
return null;
}
}.execute();
}
我需要帮助,可以使用 RxAndroid库将此AsyncTask
转换为RxJava
.
I need help to convert this AsyncTask
to RxJava
using RxAndroid library.
推荐答案
不要使用.create(),而要使用.defer()
Don't use .create() but use .defer()
Observable<File> observable = Observable.defer(new Func0<Observable<File>>() {
@Override public Observable<File> call() {
File file = downloadFile();
return Observable.just(file);
}
});
要了解更多详细信息,请参见 https://speakerdeck.com/dlew/common-rxjava-mistakes
to know more details see https://speakerdeck.com/dlew/common-rxjava-mistakes
这篇关于将AsyncTask转换为RxAndroid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文