I want to save the CountDown Ttimer value into a variable so that next time the user start the Countdowntimer Activity, it to reload at the exact elapsed time as it remained.
Here is my code and I don’t understand why it doesn’t works. (it shows my time Textbox empty)
prefs = PreferenceManager.getDefaultSharedPreferences(this);
long timer = prefs.getLong("TIME", 86400000);
new CountDownTimer(timer, 1000) {
public void onTick(long elapsed) {
System.out.print(elapsed);
long timer2=elapsed;
long hours = timer2 / hours_in_millies;
timer2 %= hours_in_millies;
long minutes = timer2 / minutes_in_millies;
timer2 %= minutes_in_millies;
long seconds = timer2 / seconds_in_millies;
time.setText(hours + ":" + minutes + ":" + seconds);
SharedPreferences.Editor editor = prefs.edit();
editor.putLong("TIME",elapsed);
editor.commit();
}
Solved: