当计时器结束时 - 返回ResultActivity

时间:2016-03-28 12:47:20

标签: java android

你可以帮我解决问题吗?当计时器结束时,用户移动到ResultActivity(例如)。这是代码

       @Override
    public void onFinish() {
        times.setText("Time is up");
    }
    @Override
    public void onTick(long millisUntilFinished) {
        // TODO Auto-generated method stub
        long millis = millisUntilFinished;
        String hms = String.format(
                "%02d:%02d:%02d",
                TimeUnit.MILLISECONDS.toHours(millis),
                TimeUnit.MILLISECONDS.toMinutes(millis)
                        - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS
                        .toHours(millis)),
                TimeUnit.MILLISECONDS.toSeconds(millis)
                        - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS
                        .toMinutes(millis)));
        System.out.println(hms);
        times.setText(hms);
    }
}

2 个答案:

答案 0 :(得分:0)

从onFinish()

调用Start活动
@Override
        public void onFinish() {
            times.setText("Время вышло");

    //Start Activity 
    Intent intent= new Intent(activityName.this, ResultActivity.class);
    startActivity(intent);
        }

答案 1 :(得分:0)

在onFinish()中使用intent启动Activity。你也可以加入额外的东西。

@Override
    public void onTick(long millisUntilFinished) {
        // TODO Auto-generated method stub
        long millis = millisUntilFinished;
        String hms = String.format(
                "%02d:%02d:%02d",
                TimeUnit.MILLISECONDS.toHours(millis),
                TimeUnit.MILLISECONDS.toMinutes(millis)
                        - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS
                        .toHours(millis)),
                TimeUnit.MILLISECONDS.toSeconds(millis)
                        - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS
                        .toMinutes(millis)));
        System.out.println(hms);
        times.setText(hms);
    }
  @Override
    public void onFinish() {
        times.setText("Time is up");
        Intent resultActivityIntent= new Intent(currentActivityName.this, ResultActivity.class);
        startActivity(resultActivityIntent);
    }