2

我正在实现一个应用程序,在该应用程序中我需要在布局中显示一个计时器。一旦计时器倒计时到 0 秒,应用程序就会继续,然后它应该自动进入另一个定义了路径的应用程序。

4

2 回答 2

2

你可以这样做并在 onFinish 中加载另一个应用程序

private class MyCount extends CountDownTimer{

    public MyCount(long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);
    }

    @Override
    public void onTick(final long millisUntilFinished) {
        long min = 0, sec = 0, totalSec = 0;
        totalSec = (millisUntilFinished/1000);
        min = totalSec/60;
        sec = totalSec%60;
        final long m = min;
        final long s = sec;
        runOnUiThread(new Runnable() {

            public void run() {
                System.out(" "+ m +"m and "+s+"s remaining.");
                                    // or Display the way you want
            }
        });

    }
    @Override
    public void onFinish() {
        //load the task you want to do
    }
}

可以这样称呼

MyCount counterr = new MyCount(sec *1000 , 1000);// sec = number of seconds
counterr.start();
于 2012-11-07T09:44:57.950 回答
1

我会用CountDownTimer这个任务。使用 onFinish 方法调用其他活动。

new CountDownTimer(timetocomplete, ticks) {
       @Override
       public void onTick(long millisUntilFinished) {

       }

       @Override
       public void onFinish() {

           // Intent to start a new activity

       }
    }.start();
于 2012-11-07T09:45:45.583 回答