I am trying to show a CountDownTimer
to user which start decreasing immediately a user press the 'START' button, but if I'm closing the activity and reopening it, the CountDownTimer is getting reset and getting start again.
I used this link to learn how to set a CountDownTimer
.
Here's how I coded it:
new CountDownTimer(ms, 1000) {
public void onTick(long millisUntilFinished) {
String hms = String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(millisUntilFinished),
TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished) % TimeUnit.HOURS.toMinutes(1),
TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) % TimeUnit.MINUTES.toSeconds(1));
holder.availableFor.setText(hms);
}
public void onFinish() {
holder.linearLayout.setVisibility(View.GONE);
holder.firebaseDatabase.child(itemID).setValue(null);
holder.geoFireReference.child(itemID).setValue(null);
}
}.start();
Please let me know how to keep the Timer going even if user closes the app.