Convert AsyncTask to RxAndroid

后端 未结 3 1789
北恋
北恋 2021-02-04 03:02

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

private static void onGetLatestStoryCollectionSuccess(final StoryColle         


        
3条回答
  •  萌比男神i
    2021-02-04 03:46

    In your case you can use fromCallable. Less code and automatic onError emissions.

    Observable observable = Observable.fromCallable(new Callable() {
            @Override
            public File call() throws Exception {
                File file = downloadFile();
                return file;
            }
        });
    

    Using lambdas:

    Observable observable = Observable.fromCallable(() -> downloadFile());
    

提交回复
热议问题