Countdown timer with pause and resume

后端 未结 8 949
小蘑菇
小蘑菇 2021-01-05 04:17

I want to do countdown timer with pause and restart.Now i am displaying countdown timer By implenting ontick() and onfinish().please help me out.HEre is th code for countdow

8条回答
  •  感情败类
    2021-01-05 04:24

    I'm using two private vars in this case:

    private long startPauseTime;
    private long pauseTime = 0L;
    
    public void pause() { 
        startPauseTime = System.currentTimeMillis(); 
    }
    
    public void resumen(){ 
        pauseTime +=  System.currentTimeMillis() - startPauseTime; 
    }
    

提交回复
热议问题