0
我在我的一項活動中有一個計時計時器,我想在第二次活動中顯示計時器已經過去的時間。我試圖使用片段,但計時器保持在第二次活動的啓動。在多個活動上計數定時器
我的定時器的代碼是:
startTime = SystemClock.uptimeMillis();
customHandler.postDelayed(updateTimerThread, 0);
private Runnable updateTimerThread = new Runnable() {
public void run() {
timeInMilliseconds = SystemClock.uptimeMillis() - startTime;
updatedTime = timeSwapBuff + timeInMilliseconds;
int secs = (int) (updatedTime/1000);
int mins = secs/60;
secs = secs % 60;
int milliseconds = (int) (updatedTime % 1000);
/* Timer.setText("" + mins + ":"
+ String.format("%02d", secs) + ":"
+ String.format("%03d", milliseconds));*/
customHandler.postDelayed(this, 0);
}
};
創建服務並將計時器放入其中並顯示來自服務的任何活動的更新結果。 – Hulk
我有這個想法,但我不知道如何創建一個後臺服務。你可以分享一些代碼嗎?這將是一個很大的幫助。 – user3626957
define - 「顯示計時器」。 – TheLostMind