您的足迹:首页 > 未分类 >RxJava2 使用笔记

RxJava2 使用笔记

        Observable<String> sender= Observable.create(new ObservableOnSubscribe<String>() {
            @Override
            public void subscribe(@NonNull ObservableEmitter<String> e) throws Exception {
                LogUtils.e(TAG," send string 1");
                e.onNext("String 1");
                LogUtils.e(TAG," send string 2");
                e.onNext("String 2");
                LogUtils.e(TAG," send onComplete");
                e.onComplete();
                LogUtils.e(TAG," send string 3");
                e.onNext("String 3");
            }
        });
        Observer<String> receiver=new Observer<String>() {
            @Override
            public void onSubscribe(@NonNull Disposable d) {
                LogUtils.e(TAG," onSubscribe");
            }
            @Override
            public void onNext(@NonNull String s) {
                LogUtils.e(TAG," onNext :"+s);
            }
            @Override
            public void onError(@NonNull Throwable e) {
                LogUtils.e(TAG," onError :"+e);
            }
            @Override
            public void onComplete() {
                LogUtils.e(TAG," onComplete  ");
            }
        };
        sender.subscribe(receiver);
运行结果:
06-23 12:31:13.632 28377-28377/jiqi.rxjavademo E/MainActivity:  onSubscribe
06-23 12:31:13.633 28377-28377/jiqi.rxjavademo E/MainActivity:  send string 1
06-23 12:31:13.633 28377-28377/jiqi.rxjavademo E/MainActivity:  onNext :String 1
06-23 12:31:13.633 28377-28377/jiqi.rxjavademo E/MainActivity:  send string 2
06-23 12:31:13.634 28377-28377/jiqi.rxjavademo E/MainActivity:  onNext :String 2
06-23 12:31:13.634 28377-28377/jiqi.rxjavademo E/MainActivity:  send onComplete
06-23 12:31:13.634 28377-28377/jiqi.rxjavademo E/MainActivity:  onComplete  
06-23 12:31:13.634 28377-28377/jiqi.rxjavademo E/MainActivity:  send string 3
本博客所有文章如无特别注明均为原创。作者:AlanWang复制或转载请以超链接形式注明转自 AlanWang的博客-专注android和蓝牙BLE技术分享
原文地址《RxJava2 使用笔记

相关推荐

发表评论

路人甲 表情
看不清楚?点图切换 Ctrl+Enter快速提交

网友评论(0)