10秒ごとに更新通知を送信するためのサンプルコードに従っています。コードは次のとおりであり、のUpdateService
ためにありAppWidgetProvider
ます。を置くThread.sleep(10*1000);
と、サービスループの予想される動作を確認できます。私は明らかに、すぐにトリガーされる根本的に間違った何かを持っています。PendingIntent
リスナーにアップデートをブロードキャストするアラームのはずです。
long nextUpdate = 10*1000;
Log.d(TAG, "Requesting next update in " + nextUpdate + " msec." );
Intent updateIntent = new Intent(ACTION_UPDATE_ALL);
updateIntent.setClass(this, UpdateService.class);
PendingIntent pendingIntent = PendingIntent.getService(this, 0, updateIntent, 0);
// Schedule alarm, and force the device awake for this update
AlarmManager alarmManager = (AlarmManager)getBaseContext().getSystemService(Context.ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(),
nextUpdate, pendingIntent);