【发布时间】:2014-12-06 16:27:43
【问题描述】:
我正在制作一个 Android 应用程序,它对您可以获得的积分数量有时间限制。但是,如果您关闭应用程序,计时器将继续运行。应用暂停时如何暂停CountDownTimer?
【问题讨论】:
标签: java android countdowntimer
我正在制作一个 Android 应用程序,它对您可以获得的积分数量有时间限制。但是,如果您关闭应用程序,计时器将继续运行。应用暂停时如何暂停CountDownTimer?
【问题讨论】:
标签: java android countdowntimer
您可以在onPause() 中使用类似的方式取消它
@Override
public void onPause()
{
super.onPause();
timer.cancel(); // timer is a reference to my inner CountDownTimer class
timer = null;
}
并使用millisUntilFinished 变量保存在SharedPreference 或其他一些持久变量中。然后再次使用该变量在onResume()中启动计时器
This answer may be helpful 如果您需要将值传递给另一个Activity。
【讨论】: