Last active
February 15, 2017 21:46
-
-
Save kwong93/66dfcad029578bfc4780548f540a0533 to your computer and use it in GitHub Desktop.
rxjava:2.0.6, rxandroid:2.0.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private List<String> getHeavyList() { | |
List<String> list = new ArrayList<>(); | |
list.add("First string"); | |
list.add("Second string"); | |
list.add("Third string"); | |
return list; | |
} | |
Single<List<String>> singleListObservable = Single.fromCallable(new Callable<List<String>>() { | |
@Override | |
public List<String> call() { | |
return getHeavyList(); | |
} | |
}); | |
Disposable disposable = singleListObservable | |
.subscribeOn(Schedulers.io()) | |
.observeOn(AndroidSchedulers.mainThread()) | |
.subscribeWith(new DisposableSingleObserver<List<String>>() { | |
@Override | |
public void onSuccess(List<String> strings) { | |
Log.i("RxJava", strings.toString()); | |
} | |
@Override | |
public void onError(Throwable e) { | |
} | |
}); | |
// on configuration changes stop callable | |
disposable.dispose(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment