坑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