我正在使用倒数计时器倒计时这是我的代码:
public class countdownnow extends Activity{
TextView tv;
private CDwnTimer countDownTimer;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.countdown_disp);
tv = (TextView)findViewById(R.id.textView1);
countDownTimer = new MalibuCountDownTimer(30000, 1050);
countDownTimer.start();
}
// CountDownTimer class
public class CDwnTimer extends CountDownTimer {
public CDwnTimer(long startTime, long interval) {
super(startTime, interval);
}
@Override
public void onFinish() {
tv.setText("00");
}
@Override
public void onTick(long millisUntilFinished) {
int convert = (int) millisUntilFinished/1000;
String testString = String.format("%02d",convert);
CharSequence cs = new String(testString);
tv.setText(cs);
}
}
}
最初这工作正常但是当我离开这个活动然后去另一个活动然后回来时,文本视图不再倒计时了吗?TextView tv 继续运行,但它没有更新。Activity 是否被释放并初始化 Textview 的相同 id?任何提示都会很棒。谢谢。