Created
January 27, 2017 15:46
-
-
Save feresr/fbecd8d39d9e77f45c43b0d5d68ccae6 to your computer and use it in GitHub Desktop.
RxJava Simple example
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
button.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
getData(new DataSubscriber()); | |
} | |
}); | |
public void getData(DataSubscriber subscriber) { | |
Subscription s = apiEndpoints.getData() | |
.subscribeOn(Schedulers.io()) | |
.observeOn(AndroidSchedulers.mainThread()) | |
.subscribe(subscriber); | |
compositeSubscriptions.add(s); | |
} | |
private class DataSubscriber extends Subscriber<Data> { | |
@Override | |
public void onCompleted() { | |
//we are done, yey! | |
} | |
@Override | |
public void onError(Throwable e) { | |
showError("oh no!"); | |
} | |
@Override | |
public void onNext(Data data) { | |
displayData(data); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment