--- android/CheckUpdates/src/dk/thoerup/checkupdates/CheckUpdates.java 2010/05/10 22:10:10 723 +++ android/CheckUpdates/src/dk/thoerup/checkupdates/CheckUpdates.java 2010/05/10 22:22:09 724 @@ -23,6 +23,7 @@ public class CheckUpdates { public static long TIMESPAN_DAY = 24*60*60*1000; // one day final static String CHECKUPDATES = "CheckUpdates"; + final static String LASTCHECK = "lastcheck"; int versionCode; String versionName; @@ -40,9 +41,10 @@ this.title = title; SharedPreferences prefs = context.getSharedPreferences(CHECKUPDATES, Context.MODE_PRIVATE); - long lastCheck = prefs.getLong("lastcheck", 0); + long lastCheck = prefs.getLong(LASTCHECK, 0); long now = System.currentTimeMillis(); //should i use android.os.SystemClock.elapsedRealtime() instead ? + Log.i(CHECKUPDATES, "Now=" + now + ", lastCheck=" + lastCheck + ", lastCheck+timespan=" + (lastCheck + TIMESPAN_DAY) ); if ( now > (lastCheck+TIMESPAN_DAY) ){ @@ -123,6 +125,14 @@ Log.i(CHECKUPDATES, "result=" + result + ", newestVersion" + newestVersion + ", versionCode=" + versionCode); if (result == true) { + + long now = System.currentTimeMillis(); + SharedPreferences prefs = context.getSharedPreferences(CHECKUPDATES, Context.MODE_PRIVATE); + //when done write + Editor edit = prefs.edit(); + edit.putLong(LASTCHECK, now); + edit.commit(); + if (newestVersion > versionCode) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(title); @@ -155,12 +165,6 @@ } - long now = System.currentTimeMillis(); - SharedPreferences prefs = context.getSharedPreferences(CHECKUPDATES, Context.MODE_PRIVATE); - //when done write - Editor edit = prefs.edit(); - edit.putLong("lastCheck", now); - edit.commit(); } }