以数组内容发送事件
private void fromOpratorTest() { //from操作符,创建以数组内容发送事件的Observable String[] observableArr = new String[]{"1", "2"}; Observable.fromArray(observableArr).subscribe(new Observer<String>() { @Override public void onSubscribe(Disposable d) { Log.d(TAG, "onSubscribe: "); } @Override public void onNext(String str) { Log.d(TAG, "onNext: "+str); } @Override public void onError(Throwable e) { Log.d(TAG, "onError: "); } @Override public void onComplete() { Log.d(TAG, "onComplete: "); } }); } 复制代码
运行效果:
com.afterchristmas.rxjavademos D/MainActivity: onSubscribe: com.afterchristmas.rxjavademos D/MainActivity: onNext: 1 com.afterchristmas.rxjavademos D/MainActivity: onNext: 2 com.afterchristmas.rxjavademos D/MainActivity: onComplete: 复制代码
参考: www.jianshu.com/p/d997805b3…