Created
January 25, 2017 01:15
-
-
Save pyeongho/b912db5c42e318f54b5941a54b7b65b7 to your computer and use it in GitHub Desktop.
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 void doSomeWork() { | |
getObservable() | |
// Run on a background thread | |
.subscribeOn(Schedulers.io()) | |
// Be notified on the main thread | |
.observeOn(AndroidSchedulers.mainThread()) | |
.subscribe(getObserver()); | |
} | |
private Observable<String> getObservable() { | |
return Observable.just("Cricket", "Football"); | |
} | |
private Observer<String> getObserver() { | |
return new Observer<String>() { | |
@Override | |
public void onSubscribe(Disposable d) { | |
Log.d(TAG, " onSubscribe : " + d.isDisposed()); | |
} | |
@Override | |
public void onNext(String value) { | |
textView.append(" onNext : value : " + value); | |
textView.append(AppConstant.LINE_SEPARATOR); | |
Log.d(TAG, " onNext : value : " + value); | |
} | |
@Override | |
public void onError(Throwable e) { | |
textView.append(" onError : " + e.getMessage()); | |
textView.append(AppConstant.LINE_SEPARATOR); | |
Log.d(TAG, " onError : " + e.getMessage()); | |
} | |
@Override | |
public void onComplete() { | |
textView.append(" onComplete"); | |
textView.append(AppConstant.LINE_SEPARATOR); | |
Log.d(TAG, " onComplete"); | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment