As shown in the following code, I would like to use RxAndroid. but I am facing two issues:
1- I want to convert the Array to observable, but the method .fromArray is not recognised
2- Why in the interface of Observer i dont have onSubscribe(Disposable d) implemented?
please let me know hopw to fix these two issues.
build gradle
compile 'io.reactivex:rxandroid:1.2.1'
compile 'io.reactivex:rxjava:1.1.9'
code:
import rx.Observable;
import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Func1;
import rx.schedulers.Schedulers;
//fromArray is not defined
private Observable<String> getAnimalsObservable() {
return Observable.fromArray(
"Ant", "Ape",
"Bat", "Bee", "Bear", "Butterfly",
"Cat", "Crab", "Cod",
"Dog", "Dove",
"Fox", "Frog");
}
//why in the following interface, i dont have onSubscribe(Disposable d)
private Observer<String> getAnimalsObserver() {
return new Observer<String>() {
@Override
public void onNext(String s) {
Log.d(TAG, "Name: " + s);
}
@Override
public void onError(Throwable e) {
Log.e(TAG, "onError: " + e.getMessage());
}
@Override
public void onCompleted() {
Log.d(TAG, "All items are emitted!");
}
};
}
from.onSubscribe(Disposable)was introduced in RxJava 2 because of a complete rewrite and rearchitecting of the components. Please make sure you read the javadocs and look at what your IDE's code completion suggests.