所以,我的活动中有一个倒数计时器。现在,我有一个按钮可以打开另一个活动。单击该按钮时,我需要存储当前的倒计时计时器值,并从该保存的值开始在第二个活动中启动倒计时计时器。我正在考虑使用 Intent 来打发时间,但我不知道要传递什么价值。我怎样才能做到这一点?我的计时器:
public String formatTime(long millis) {
String output = "00:00";
long seconds = millis / 1000;
long minutes = seconds / 60;
seconds = seconds % 60;
minutes = minutes % 60;
String sec = String.valueOf(seconds);
String min = String.valueOf(minutes);
if (seconds < 10)
sec = "0" + seconds;
if (minutes < 10)
min= "0" + minutes;
output = min + " : " + sec;
return output;
}
在 onCreate 方法中:
// New timer for 40 minutes, starts after initialization
new MyCount(2400000, 1000)
{
// Updates the text on your "scoreboard" every second
public void onTick(long millisUntilFinished)
{
vreme.setText("" + formatTime(millisUntilFinished));
}
public void onFinish()
{
}
}.start();
}
public class MyCount extends CountDownTimer {
public MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
public void onFinish() {
}
public void onTick(long millisUntilFinished) {
vreme.setText("" + millisUntilFinished / 1000);
}