Rxjava2.0 -map() Consumer() Function() 메서드

2203 단어 andriod
관련 기사:
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------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 {

                    }
                });

좋은 웹페이지 즐겨찾기