Я следую примеру кода для отправки уведомления об обновлении каждые 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);