美文网首页安卓
RxJava学习笔记

RxJava学习笔记

作者: 汇源可乐 | 来源:发表于2018-03-27 17:37 被阅读9次

    Where I study 'RxJava' from?

    http://gank.io/post/560e15be2dca930e00da1083#toc_1

    最近升级到android studio 3.2,发现google正在推崇使用implementation而不是使用compile

    引用库了。如果在使用过程中发现compile报错的话,可以使用implementation

    RxJava 的github地址:https://github.com/ReactiveX/RxJava

    现在引用RxJava的依赖:compile"io.reactivex.rxjava2:rxjava:2.1.12"

    What is RxJava?

    一个词:异步

    "a library for composing asynchronous and event-based programs using observable sequences for the Java VM"(一个在 Java VM 上使用可观测的序列来组成异步的、基于事件的程序的库)

    Why people would like to use RxJava?

    因为:简洁

    RxJava随着程序逻辑变得越来越复杂,它依然能够保持简洁。

    对比原始代码与RxJava代码:

        @Override
        public void run() {
            super.run();
            for (File folder : folders) {
                File[] files = folder.listFiles();
                for (File file : files) {
                    if (file.getName().endsWith(".png")) {
                        final Bitmap bitmap = getBitmapFromFile(file);
                        getActivity().runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                imageCollectorView.addImage(bitmap);
                            }
                        });
                    }
                }
            }
        }
    }.start();
    

    相关文章

      网友评论

        本文标题:RxJava学习笔记

        本文链接:https://www.haomeiwen.com/subject/qtmscftx.html