码迷,mamicode.com
首页 > 其他好文 > 详细

Rxlifecycle(三):坑

时间:2016-01-06 20:02:43      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

 

坑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

Rxlifecycle(三):坑

标签:

原文地址:http://www.cnblogs.com/liulipeng/p/5106506.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!