RXJava(倒计时)

 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) {

                    }
                });

 

上一篇:手机app端扫描二维码登录web端的解决方法,前后端分离,uniapp,基于token


下一篇:Go语言(学习)——接口源码分析