Skip to content

Instantly share code, notes, and snippets.

@kevalpatel2106
Last active April 4, 2020 09:25
Show Gist options
  • Save kevalpatel2106/c1527a89cea2add156e4709f183da189 to your computer and use it in GitHub Desktop.
Save kevalpatel2106/c1527a89cea2add156e4709f183da189 to your computer and use it in GitHub Desktop.
Observable<String> database = Observable //Observable. This will emit the data
.just(new String[]{"1", "2", "3", "4"}); //Operator
Observer<String> observer = new Observer<String>() {
@Override
public void onCompleted() {
//...
}
@Override
public void onError(Throwable e) {
//...
}
@Override
public void onNext(String s) {
//...
}
};
database.subscribeOn(Schedulers.newThread()) //Observable runs on new background thread.
.observeOn(AndroidSchedulers.mainThread()) //Observer will run on main UI thread.
.subscribe(observer); //Subscribe the observer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment