In my application I kept pause button and start button. By default I set the timer to 50sec. When the timer is running I wrote the onclick action code for each button...i.e when pause button is clicked the time is pausing and again when start button is clicked it is again starting from 50sec. But it should start from the time where it is paused. How can I do that?
Please help me....thanks in advance.......
My Code:
long timervalue = 50000;
btn13 = (ImageView) findViewById(R.id.pause);
btn14 = (ImageView) findViewById(R.id.resume);
final CountDownTimer Counter1 = new CountDownTimer(timervalue, 1000) {
public void onTick(long millisUntilFinished) {
time.setText(formatTime(millisUntilFinished));
btn13.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Counter1.cancel();
}
});
btn14.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Counter1.start();
}
});
}
public void onFinish()
{
Counter1.cancel();
}
};
public String formatTime(long millis) {
String output = "00:00";
long seconds = millis / 1000;
// long minutes = seconds / 60;
seconds = seconds % 60;
// minutes = minutes % 60;
String secondsD = String.valueOf(seconds);
// String minutesD = String.valueOf(minutes);
if (seconds < 10)
secondsD = "0" + seconds;
// if (minutes < 10)
// minutesD = "0" + minutes;
output = secondsD;
return output;
}