title: Android, reset a value everyday
body: <p>I am developing a timer app that works in block of times (pomodoros) and I'd like to have a variable that keeps track of the number of blocks passed everyday, so it keeps counting within the same day but goes back to zero the day after. </p>
  
  <p>I was thinking of implementing this by saving the "last recorded day" when updating this value, and everytime the program starts, check it agaisnt the current date and act accordingly. So I have:</p>
  
  <pre><code>    public void saveDailyPomodoros() {
      SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
      int currentDay = Calendar.getInstance().get(Calendar.DAY_OF_YEAR);
      sharedPrefs.edit().putInt("dailyPomodoros", dailyPomodoros).commit();
      sharedPrefs.edit().putInt("lastRecordedDay", currentDay).commit();
      showDailyPomodoros.setText(String.valueOf(dailyPomodoros));
  }
  </code></pre>
  
  <p>which saves the value (I call this function when I change it), and</p>
  
  <pre><code>    public void updateSettings() {
      SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
      ...
  
      int currentDay = Calendar.getInstance().get(Calendar.DAY_OF_YEAR);
      int lastRecordedDay = sharedPrefs.getInt("lastRecordedDay", 0);
      if (currentDay != lastRecordedDay) {
          dailyPomodoros = 0;
          saveDailyPomodoros();
      }
  }
  </code></pre>
  
  <p>That is called at the start of the program and when the user exits the preference screen.</p>
  
  <p>It works fine on this second case, however if I kill the app / reboot device it doesn't work, even if the other preferences are being saved (I have got shared preferences for custom ringtones that are not resetted).</p>
  
  <p>What am I doing wrong?</p>