How to start timer after make cancelling timer?

Viewed 25

I had using timer I make cancel or stop timer on button click and then I want to start again timer on click start button.How can doing start timer after cancelling timer?

           timerLoop = new Timer();
            hourlyTaskLoop = new TimerTask() {
                @Override
                public void run() {

                }
            };

            timerLoop.schedule(hourlyTaskLoop, 0l, 1000);

stop timer

            timerLoop.cancel();
            hourlyTaskLoop.cancel();
1 Answers

I hope this could help you

Stopwatch stopwatch = Stopwatch.createStarted();

void startThreadUpdateTimer(){}
Timer T = new Timer();
T.scheduleAtFixedRate(new TimerTask() {
    @Override
    public void run() {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                String workingTime = "Your effort is " + sw.toString() + 
                     " till now for the day";                        
            }
        });
    }
}, 1000, 1000);
}

public void pause(){
if(stopwatch.isRunning()){
    stopwatch.stop();
}
}

public void resume(){
if(!stopwatch.isRunning()){
    stopwatch.start();
}
}
Related