Skip to content

Instantly share code, notes, and snippets.

@Nyame123
Last active November 1, 2020 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nyame123/8826d8314ac71fef359722fee65a912f to your computer and use it in GitHub Desktop.
Save Nyame123/8826d8314ac71fef359722fee65a912f to your computer and use it in GitHub Desktop.
Using create method to create Observables and subscribe
private void createObservablesAndSubscribing() {
Observable observable = Observable.create(new ObservableOnSubscribe() {
@Override
public void subscribe(@NonNull ObservableEmitter emitter) {
emitter.onNext("Emitting new Stuff !!");
emitter.onComplete();
}
});
observable.subscribe(new Observer<String>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
}
@Override
public void onNext(String o) {
Log.d("RxJava Create", o);
}
@Override
public void onError(@NonNull Throwable e) {
}
@Override
public void onComplete() {
Log.d("RxJava Create","Observable consumed");
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment