Rxjava2.0 -map() Consumer() Function()方法

相关文章:

Android 知识点总结(目录)

Rxjava2.0 -基本创建

Rxjava2.0 - 压背

Rxjava2.0 -map() Consumer() Function()方法

Rx1.0-----------Rx2.0

Func1--------Function

 Observable.just("asd")
                .map(new Function() {
                    @Override
                    public Bitmap apply(String s) throws Exception {
                        return getMap(s);
                    }
                }).subscribe(new Consumer() {
            @Override
            public void accept(Bitmap bitmap) throws Exception {

            }
        }, new Consumer() {
            @Override
            public void accept(Throwable throwable) throws Exception {

            }
        }, new Action() {
            @Override
            public void run() throws Exception {

            }
        });
        
 private Bitmap getMap(String s ){
        return BitmapFactory.decodeFile(s);
    }

Rx1.0-----------Rx2.0

Action1--------Action
Action1--------Consumer
Action2--------BiConsumer
后面的Action都去掉了,只保留了ActionN

  Observable.create(new ObservableOnSubscribe() {
            @Override
            public void subscribe(ObservableEmitter e) throws Exception {

                e.onNext("xxxxxxxxxxx");

            }
        })
                .subscribe(new Consumer() {
                    @Override
                    public void accept(String s) throws Exception {
                        Log.e("info", "accept" + s);
                        throw new NullPointerException("mock exception !");
                    }
                }, new Consumer() {  //onError
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        Log.i("info", "accept: " + throwable);
                    }
                }, new Action() { //onComplete
                    @Override
                    public void run() throws Exception {

                    }
                });

你可能感兴趣的:(andriod)