Alarm fires on "sleeping" Android device
<p>I am writing an Android AppWidget that needs to be updated frequently (yes, I know, shouldn't do that, whatever...). I would like it to be updated only if it is visible, but annoyingly there seems to be nothing similar to <code>WallpaperService.Engine.onVisibilityChanged(boolean visible)</code>.</p>

<p>The suggested approach here is to set up an alarm with <code>AlarmManager.setRepeating(AlarmManager.RTC, firstShot, interval, pendingIntent)</code> that triggers the update every <code>interval</code> milliseconds. This would at least not wake the device when it is asleep.</p>

<p>That's just what I did. My <code>PendingIntent</code> looks like this:</p>

<pre><code>final Intent intent = new Intent(context, CountdownWidgetService.class);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);

final PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
</code></pre>

<p>The <code>CountdownWidgetService</code> logs a message every time it is triggered by the alarm. The log message shows up even when the device should be asleep - but that's just what I thought was not supposed to happen. Where is my mistake?</p>
