Reputation: 186
in my application i have a timer.i want the timer to get paused by itself after 60 secs.can any one help me out..this is what i have done
private Runnable updateTimerThread = new Runnable() {
public void run() {
timeInMilliseconds = SystemClock.uptimeMillis() - startTime;
updatedTime = timeSwapBuff + timeInMilliseconds;
int secs = (int) (updatedTime / 1000);
mins = secs / 60;
secs = secs % 60;
int milliseconds = (int) (updatedTime % 1000);
/*timerValue.setText("" + mins + ":"
+ String.format("%02d", secs) + ":"
+ String.format("%03d", milliseconds));*/
timerValue.setText("" + mins + ":"
+ String.format("%02d", secs) );
customHandler.postDelayed(this, 0);
}
};
Upvotes: 0
Views: 80
Reputation: 186
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startCountDownTimer();
}
});
protected void startCountDownTimer() {
cdTimer = new CountDownTimer(total, 1000) {
public void onTick(long millisUntilFinished) {
//update total with the remaining time left
total = millisUntilFinished;
tv.setText("seconds remaining: " + millisUntilFinished/ 1000);
}
public void onFinish() {
tv.setText("done!");
}
}.start();
}
Upvotes: 0
Reputation: 3701
Use CountDownTimerwithPause class to pause and resume the timer. refere this
Pause CountDownTimer in Android when activity is not in front
override onTick method of it.when timmer reaches 60000 call pause() with timer object.
Upvotes: 1