private Disposable subscribe;
private void rxjavaInterval() {
final Long time = 5L;
subscribe = Observable.interval(1, TimeUnit.SECONDS)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<Long>() {
@Override
public void accept(Long aLong) throws Exception {
Log.e("TAG", "倒计时:" + aLong);
if (aLong < time && !subscribe.isDisposed()) {
tv.setText("记录改变生活" + (time - aLong - 1));
} else {
Intent intent = new Intent(WelcomActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
}
});
}
@Override
protected void onDestroy() {
super.onDestroy();
subscribe.dispose();
subscribe = null;
}
网友评论