我正在按照示例代码每 10 秒发送一次更新通知。代码如下,它位于一个UpdateService
for 中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);