RxJava/RxAndroid : takeLast 深碍√TFBOYSˉ_ 2023-10-17 17:53 47阅读 0赞 **RxJava/RxAndroid : takeLast** package zhangphil.book; import android.os.SystemClock; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import io.reactivex.Observable; import io.reactivex.Observer; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; public class MainActivity extends AppCompatActivity { private String TAG = "输出"; private Observer<Integer> mObserver = new Observer<Integer>() { @Override public void onSubscribe(Disposable d) { } @Override public void onNext(Integer i) { Log.d(TAG, "onNext:" + i); } @Override public void onComplete() { Log.d(TAG, "onComplete"); } @Override public void onError(Throwable e) { Log.e(TAG, e.toString(), e); } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Integer[] numbers = new Integer[]{0, 1, 2, 3, 4}; Observable.fromArray(numbers) .takeLast(2) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribeWith(mObserver); } } output: 01-19 14:43:10.401 6018-6018/zhangphil.book D/输出: onNext:3 01-19 14:43:10.402 6018-6018/zhangphil.book D/输出: onNext:4 01-19 14:43:10.402 6018-6018/zhangphil.book D/输出: onComplete
相关 RxJava/RxAndroid : takeLast RxJava/RxAndroid : takeLast package zhangphil.book; import android.os 深碍√TFBOYSˉ_/ 2023年10月17日 17:53/ 0 赞/ 48 阅读
还没有评论,来说两句吧...