Preface Rx series of articles

  1. RxJava met
  2. RxJava overview
  3. RxJava operator
  4. Observables create
  5. The Observer’s creation
  6. RxJava various ways to unsubscribe

From

Send events as array contents

  private void fromOpratorTest(a) {
        // The from operator creates an Observable that sends events as array contents
        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(a) {
                Log.d(TAG, "onComplete: "); }}); }Copy the code

Operation effect:

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: 
Copy the code

Reference: www.jianshu.com/p/d997805b3…