Skip to content

Instantly share code, notes, and snippets.

@juankg214
Created June 9, 2021 03:31
Show Gist options
  • Select an option

  • Save juankg214/72b16f25698e603d329637bbb2cee74f to your computer and use it in GitHub Desktop.

Select an option

Save juankg214/72b16f25698e603d329637bbb2cee74f to your computer and use it in GitHub Desktop.
private Subscription subscription;
private void onButtonClicked(Button button) {
subscription = networkService.getObservableUser(123)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<User>() {
@Override public void call(User user) {
nameTextView.setText(user.getName());
// ... set other views
}
});
}
@Override protected void onDestroy() {
if (subscription != null && !subscription.isUnsubscribed()) {
subscription.unsubscribe();
}
super.onDestroy();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment