In RxJava2, a solution is possible:
Version with lambdas:
Single.fromCallable(() -> loadInBackground()) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe((myObject) -> { updateUi(myObject) });
Version without lambdas:
Single.fromCallable(new Callable<Object>() { @Override public Object call() throws Exception { return loadInBackground(); } }) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Consumer<Object>() { @Override public void accept(Object myObject) throws Exception { updateUi(myObject); } });
Examples of methods:
private Object loadInBackground() {
source share