• Rxlifecycle(三):坑


     

    坑1

        Observable.just("hello world!")
                .compose(this.<String>bindUntilEvent(ActivityEvent.PAUSE))
                .flatMap(new Func1<String, Observable<Long>>() {
                    @Override
                    public Observable<Long> call(String s) {
                        return Observable.interval(1, TimeUnit.SECONDS);
                    }
                })
    
                .subscribe(new Action1<Long>() {
                    @Override
                    public void call(Long aLong) {
                        Log.i(TAG, "....oh,oh,no!!..........." + aLong);
                    }
                });

    activity生命周期paused的时候

    Log.i(TAG, "....oh,oh,no!!..........." + aLong); 

    还会执行么??会会...

    如果你想全部都不执行:

    Observable.just("hello world!")
                .flatMap(new Func1<String, Observable<Long>>() {
                    @Override
                    public Observable<Long> call(String s) {
                        return Observable.interval(1, TimeUnit.SECONDS);
                    }
                })
                //fuck....here
                .compose(this.<Long>bindUntilEvent(ActivityEvent.PAUSE))
                .subscribe(new Action1<Long>() {
                    @Override
                    public void call(Long aLong) {
                        Log.i(TAG, "....oh,oh,no!!..........." + aLong);
                    }
                });

    坑2

        Observable.interval(1, TimeUnit.SECONDS)
                .doOnUnsubscribe(new Action0() {
                    @Override
                    public void call() {
                        Log.i(TAG, "Unsubscribing subscription ......");
                    }
                })
                .doOnNext(new Action1<Long>() {
                    @Override
                    public void call(Long aLong) {
                        Log.i(TAG, "........fuck..........." + aLong);
                    }
                })
                .flatMap(new Func1<Long, Observable<String>>() {
                    @Override
                    public Observable<String> call(Long aLong) {
                        return Observable.just(aLong + "");
                    }
                })
                .compose(this.<String>bindUntilEvent(ActivityEvent.PAUSE))
                .subscribe(new Action1<String>() {
                    @Override
                    public void call(String num) {
                        Log.i(TAG, "..........shit..........." + num);
                    }
                });

    activity在paused的时候,

    Log.i(TAG, "........fuck..........." + aLong);
    Log.i(TAG, "..........shit..........." + num);

    都不会执行...

    而且会unsubscribe

  • 相关阅读:
    检测主机存活
    centos7 安装python3
    zbb20180103 git 配置用户名和邮箱
    zbb20171215 git 版本回退
    zbb20171215 bootstrap model 模态框
    zbb20171215 MyBatis报错: Parameter '*' not found. Available parameters are [1, 0, param1, param2]
    zbb20171215 thymeleaf th:attr
    zbb20171215ztree ztree出现$.fn.zTree is undefined错误的解决办法
    zbb20171215 bootstrap 日期控件.rar
    zbb20171215 oracle replace 替换单引号
  • 原文地址:https://www.cnblogs.com/liulipeng/p/5106506.html
Copyright © 2020-2023  润新知