我想實現一個CountDownTimer發佈可視文本倒計時,直到我到0,然後發送特定的消息。一切工作正常,直到我達到3秒鐘,它調用我的done()方法兩次;一次只剩3秒鐘,一次計數器完成。程序與CountDownTimer很好,直到有3秒左右,然後它調用兩次
我確定調用done()的唯一時間是在此CountDownTimer()中的onFinish()被調用時。我不知道它爲什麼要兩次打電話,而且始終在同一時間。
我的Java代碼:
mainCounter = new CountDownTimer(30000, 1000){
@Override
public void onTick(long millisUntilDone){
int hours = (int) (millisUntilDone/3600000);
int mins = 0, secs = 0;
long timeLeft = millisUntilDone % 3600000;
if((int)timeLeft != 0){
mins = (int) (timeLeft/60000);
}
long timeLeftStill = timeLeft % 60000;
if((int)timeLeftStill != 0){
secs = (int) (timeLeftStill/1000);
}
((TextView)findViewById(R.id.timer_label)).setText("You have " + hours + " hours, " + mins + " mins, " + secs + " secs left");
}
@Override
public void onFinish() {
// Send Message, Out of Time
((TextView)findViewById(R.id.timer_label)).setText("MESSAGE!");
num++;
done(); //My Own Method
this.cancel();
}
}.start();
我有一個完美的作品另一個櫃檯,我評論它,以確保它不會影響這個計數器,就像我說這個人正常工作,直到我去還剩3秒。
Trail.java文件中的行「178」是什麼?你的應用中是否有GPS功能?爲什麼要調整'OnLocationChange'? –
第178行是其他((TextView)findViewById(R.id.locat_label))。setText(「Other message!」);我打算在LogCat中添加LogCat,表示它是第100行,但意外添加了註釋掉的那一個。是的,我正在以極快的速度工作。 – zgc7009
如果它不是你不願意展示的那個,請添加正確的一個。 –