Fshamri Fshamri - 1 year ago 168
Android Question

Convert AsyncTask to RxAndroid

I have the following method to post response to UI using otto and


private static void onGetLatestStoryCollectionSuccess(final StoryCollection storyCollection, final Bus bus) {
new AsyncTask<Void, Void, Void>() {
protected Void doInBackground(Void... params) {
bus.post(new LatestStoryCollectionResponse(storyCollection));
return null;

I need help to convert this
using RxAndroid library.

Answer Source

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);

to know more details see https://speakerdeck.com/dlew/common-rxjava-mistakes

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download