RxJava的事件序列
![这里写图片描述](https://img-blog.csdn.net/20160710210526267)
Observable.create(new Observable.OnSubscribe<String>() {
@Override
public void call(Subscriber<? super String> subscriber) {
subscriber.onNext("hello");
subscriber.onCompleted();
}
}).subscribe(new Observer<String>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(String s) {
}
});
Observable.just("hello","are you ok ?").subscribe(new Observer<String>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(String s) {
}
});
String[] array = {"hello","java"};
Observable.from(array).subscribe(subscribe);
@Override
protected void onDestroy() {
super.onDestroy();
subscribe.unsubscribe();
}
public Subscriber<String> subscribe = new Subscriber<String>() {
@Override
public void onStart() {
super.onStart();
}
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(String s) {
}
};
Observable.from(array).subscribe(new Action1<String>() {
@Override
public void call(String s) {
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
}
}, new Action0() {
@Override
public void call() {
}
});