title: Calling a method when a new day is detected
body: <p>I want my application to detect when it is a new day upon startup.  If it is a new day I want it to start a new activity and repeat the cycle. for the Next Day.</p>
  
  <p>I start with a calendar instance getting the day of year.</p>
  
  <pre><code>Calendar c = Calendar.getInstance();
          int thisDay = c.get(Calendar.DAY_OF_YEAR);
          long todayMillis = c.getTimeInMillis();
  </code></pre>
  
  <p>I then store it in a shared preferences and get another date</p>
  
  <pre><code>SharedPreferences prefs = PreferenceManager
                  .getDefaultSharedPreferences(this);
          long last = prefs.getLong("date", System.currentTimeMillis());
          c.setTimeInMillis(last);
          int lastDay = c.get(Calendar.DAY_OF_YEAR);
  </code></pre>
  
  <p>I am having trouble running creating the check and looping it everyday.</p>
  
  <pre><code>if (lastDay != thisDay) {
          scheduleAlarm();
          SharedPreferences.Editor edit = prefs.edit();
          edit.putLong("date", todayMillis);
          edit.commit();
  
  }
  </code></pre>
  
  <p>My solution is below.</p>
  
  <pre><code>Calendar c = Calendar.getInstance();
          int thisDay = c.get(Calendar.DAY_OF_YEAR);
          long todayMillis = c.getTimeInMillis();
  
          SharedPreferences prefs = PreferenceManager
                  .getDefaultSharedPreferences(this);
          long last = prefs.getLong("date", System.currentTimeMillis());
  
          c.setTimeInMillis(last);
          int lastDay = c.get(Calendar.DAY_OF_YEAR);
          // Toast.makeText(getApplicationContext(),
          // "lastday " + lastDay + "thisDay " + thisDay, Toast.LENGTH_LONG)
          // .show();
          if (lastDay == thisDay) {
              scheduleAlarm();
              SharedPreferences.Editor edit = prefs.edit();
              edit.putLong("date", todayMillis + 86400000);
              edit.commit();
          }
  </code></pre>