简单实现倒计时跳转

几秒后自动跳转

public class MainActivity2 extends Activity implements OnClickListener {
    private int a = 5;
    private TextView text;
    private Handler handler = new Handler() {
        public void handleMessage(android.os.Message msg) {
            if (msg.what == 0) {
                if (a > 0) {
                    a--;
                    text.setText(a + "秒后进入主页面");
                    handler.sendEmptyMessageDelayed(0, 1000);
                } else {
                    //如果a<0的话就跳转页面
                    Intent intent = new Intent(MainActivity2.this, MainActivity3.class);
                    startActivity(intent);
                }

            }


        }

        ;
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        //找到控件

        text = (TextView) findViewById(R.id.text02);

        //发一个延迟的空消息
        handler.sendEmptyMessageDelayed(0, 1000);
        
    }
}



阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页