samedi 28 mars 2015

Count up timer android

I want to use count up timer in android for long hours...


Currently, I am using this code, but after some hours, say after 10 hours, the format goes like 10 : 650 :56 (hh:mm:ss)... for lesser time, it works perfectly...



private Runnable updateTimerMethod = new Runnable() {

public void run() {
timeInMillies = SystemClock.uptimeMillis() - startTime;

finalTime = timeSwap + timeInMillies;

int seconds = (int) (finalTime / 1000);
int minutes = seconds / 60;
int hours = minutes / 60;
seconds = seconds % 60;
int milliseconds = (int) (finalTime % 1000);

String timer = ("" + String.format("%02d", hours) + " : "
+ String.format("%02d", minutes) + " : "
+ String.format("%02d", seconds));

myHandler.postDelayed(this, 0);

sendLocalBroadcast(timer);

}

};

Aucun commentaire:

Enregistrer un commentaire