How to properly handle onError inside RxJava (Android)?

后端 未结 3 1415
南笙
南笙 2021-01-01 09:56

I\'m getting a list of installed apps on the device. It\'s a costly operation, so I\'m using Rx for that:

    Observable observable = Observable         


        
3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-01 10:02

    .doOnError() is an operator, and is not as such a part of the Subscriber.

    Therefore, having a .doOnError() does not count as an implemented onError().

    About the question in one of the comments, of course it is possible to use lambdas.

    In this case simply replace

    .doOnError(throwable -> L.e(TAG, "Throwable " + throwable.getMessage()))
    .subscribe(s -> createListView(s, view))
    

    with

    .subscribe(s -> createListView(s, view),
        throwable -> L.e(TAG, "Throwable " + throwable.getMessage()))
    

提交回复
热议问题