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();
}
I need help to convert this AsyncTask
to RxJava
using RxAndroid library.
Don't use .create() but use .defer()
to know more details see https://speakerdeck.com/dlew/common-rxjava-mistakes
This is an example for a file download task using RxJava
Usage:
This would download the file on a new thread and notify you on the main thread.
OnSubscribeFunc
was deprecated. Code updated to useOnSubscribe
insted. For more info see issue 802 on Github.Code from here.
In your case you can use
fromCallable
. Less code and automaticonError
emissions.Using lambdas: