必要なのはこれです:最後の日付を表す長い値を持つ
A。
A。_SharedPreference
Calendar
アクティビティが開始されると(onCreate()メソッドではこれに適しているようです)、新しいを取得できますCalendar。現在の日付が表示され、その日を抽出できます。
Calendar c = Calendar.getInstance();
int thisDay = c.get(Calendar.DAY_OF_YEAR); //You can chose something else to compare too, such as DATE..
long todayMillis = c.getTimeInMillis(); //We might need this a bit later.
次に、前回から保存された可能性のある値を読み取り、カレンダーをこの値に設定してから、これを今日と比較します。
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
long last = prefs.getLong("date", 0); //If we don't have a saved value, use 0.
c.setTimeInMillis(last);
int lastDay = c.get(Calendar.DAY_OF_YEAR);
if( last==0 || lastDay != thisDay ){
//New day, update TextView and preference:
SharedPreferences.Editor edit = prefs.edit();
edit.putLong("date", todayMillis);
edit.commit();
}