final int count = 3;
Observable.interval(0, 1, TimeUnit.SECONDS)
.take(count + 1)
.map(new Func1<Long, Long>() {
@Override
public Long call(Long aLong) {
return count - aLong;
}
})
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<Long>() {
@Override
public void onNext(Long num) {
Log.i("Timer","剩余" + num + "秒");
sj.setText(num+"");
if(num==0)
{
Toast.makeText(MainActivity.this, "222", Toast.LENGTH_SHORT).show();
Intent intent=new Intent(MainActivity.this,Main2Activity.class);
startActivity(intent);
}
}
@Override
public void onCompleted() {
}
@Override
public void one rror(Throwable e) {
}
});