私は解決策を考え出しました。データをフェッチすると、以下が行われ
...
editPrefs.putLong("fetchTime", System.currentTimeMillis());
アプリケーションが起動し、データが正常に要求されると、それは今ん..
(注:ページがあります「Australia/ACT」は、これらのゾーンが通過するタイムゾーンです)
(オーストラリア東部夏時間)午後9時に更新されます。
//create calendar date for update threshold based on last fetch time preference
Calendar updateThresh = new GregorianCalendar(TimeZone.getTimeZone("Australia/ACT"));
updateThresh.setTimeInMillis(prefs.getLong("fetchTime", 0));
//increment day if last fetch was >= 9pm of that day
if (updateThresh.get(Calendar.HOUR_OF_DAY) >= 21)
updateThresh.add(Calendar.DAY_OF_MONTH, 1);
//set time to 9:00:00pm
updateThresh.set(Calendar.HOUR_OF_DAY , 21);
updateThresh.set(Calendar.MINUTE , 0);
updateThresh.set(Calendar.SECOND , 0);
//check if current date is before or after
if (updateThresh.before(new GregorianCalendar(TimeZone.getTimeZone("Australia/ACT"))))
{
//update needed (fetch data)
}
else
{
//update not needed (show message)
}
これは正常に動作するようです。私はオーストラリア/ ACTに設定されたDateFormatを使ってテストしました。フェッチ時に設定されている別のカレンダーオブジェクトを作成し、使用して:これは私が自分の携帯電話のタイムゾーンの設定をいじっても、一貫して正しい出力を示し
DateFormat df = DateFormat.getDateTimeInstance();
df.setTimeZone(TimeZone.getTimeZone("Australia/ACT"));
testTextField.setText("Last fetch in East AU time: " + df.format(fetchTime.getTimeInMillis()) +
"\nUpdate threshold in East AU time: " + df.format(updateThresh.getTimeInMillis()));
...私は、このソリューションの作品はかなり確信していますだから、私はそれを正しい/受け入れているとマークします - しかし、誰かがエラーに気づいたり、より良い提案があれば、気軽に投稿してください! :)
私はサービスがどのように役立つかわかりません...アプリケーションは現在、起動時にデータを取得しようとします。その時点で、そうするかどうかをテストするチェックを組み込みたい(つまり、ページが最後の更新のタイムスタンプ以降に更新された場合)。 – Greg