首页 > 代码库 > 使用Timer控制一定时间内跳转到新的Activity

使用Timer控制一定时间内跳转到新的Activity

使用Timer控制一定时间内跳转到新的Activity
标签: Android

[1].[代码] [Java]代码 跳至 [1]

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
@Override
    protectedvoid onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_frist);
        //1.创建Timer对象
        Timer timer = newTimer();
        //3.创建TimerTask对象
        TimerTask timerTask = newTimerTask() {
            @Override
            publicvoid run() {
                // TODO Auto-generated method stub
                Intent intent = newIntent(FristActivity.this,LoginActivity.class);
                startActivity(intent);
                finish();
            }
        };
        //2.使用timer.schedule()方法调用timerTask,定时3秒后执行run
        timer.schedule(timerTask,3000);
    }

使用Timer控制一定时间内跳转到新的Activity