I want to do something that i am not sure can be done, and so far i haven't found any good answers to my question.
Here is my situation:
- I have implemented Timer as a Handler that has Runnable that is calling itself every 1s.
- I need now to implement a method like Timer.restart() that can restart my Runnable's params.
Here is my code so you can see it, and better understand what i have tried to achieve
private Runnable rStartCPRTick = new Runnable() {
public int seconds = 0;
public int minutes = 0;
public int hours = 0;
@Override
public void run() {
if(++seconds%60 == 0) //increases the time by one second
if(++minutes%60 == 0)
hours++;
mActivity.updateCPRTime(formatHHMMSS(hours,minutes,seconds));
mStartCodeHandler.postDelayed(this,1000); // tick again in 1s
}
public void restartCPRTick(){
seconds = 0;
minutes = 0;
hours = 0;
}
};
My runnable, i want to be able to call resetCPRTick() from outside Runnable and then call run that starts from the beggining.
Is such thing possible?
Thanks!!
Aucun commentaire:
Enregistrer un commentaire