我有一个带有CountDownTimer对象的片段,当片段进入后台时我会暂停计时器,然后当片段再次进入前景时恢复它。这是我的代码:
@Override
public void onPause() {
super.onPause();
active = false;
try {
synchronized (countDownTimer) {
countDownTimer.wait();
Log.i("TIMER", "wait");
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void onResume() {
super.onResume();
if (countDownTimer != null) {
countDownTimer.notifyAll();
Log.i("TIMER", "notify");
}
}
这样,当我将片段放入后台时,计时器会停止倒计时,但是当我回想起前景时不会重新启动。怎么了?