title: Updating widget with service
body: <p>Based on this <a href="http://www.gotoquiz.com/web-coding/programming/android-development/how-to-make-an-android-home-screen-widget-update-only-when-visible/" rel="nofollow">tutorial</a> I've created a modified version of my own widget. Problem is now that the AlarmManager.setRepeating is not firing the intent in intervals. It seems to me that the Reciever isn't even receiving that Intent.</p>
  
  <p>To be more precise, I have </p>
  
  <ul>
  <li>WidgetActivity extending AppWidgetProvider</li>
  <li>WidgetUpdate extending IntentService</li>
  <li>WidgetAlarmReceiver extending BroadcastReceiver</li>
  </ul>
  
  <p>WidgetActivity correctly fires WidgetUpdate class in which I have that AlarmManager who has to communicate with BroadcastReceiver in intervals (30sec) when the widget is on active screen.</p>
  
  <p>WidgetUpdate.class</p>
  
  <pre><code>public class WidgetUpdate extends IntentService{
  public WidgetUpdate() {
      super(null);
  }
  
  public static int UPDATE_FREQUENCY_SEC = 30;
  
  @Override
  public void onCreate() {
      super.onCreate();
      AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
  
      PendingIntent alarmIntent = alarmIntent();
  
      long timeToRefresh = SystemClock.elapsedRealtime() + UPDATE_FREQUENCY_SEC * 1000;
      alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME,
                                       timeToRefresh,
                                       UPDATE_FREQUENCY_SEC * 1000,
                                       alarmIntent);
  }
  private PendingIntent alarmIntent() {
      Intent intentToFire = new Intent(WidgetAlarmReceiver.ACTION_REFRESH_ALARM);
      PendingIntent alarmIntent = PendingIntent.getBroadcast(this, 0, intentToFire, 0);
      return alarmIntent;
  }
  @Override
  protected void onHandleIntent(Intent intent) {
      PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
  
      if (!pm.isScreenOn()) {
          cancel();
      }
      else {
          WidgetActivity widget = new WidgetActivity();
          widget.updateWidget(getBaseContext());
      }
  
  }
  </code></pre>
  
  <p>WidgetAlarmReceiver.class</p>
  
  <pre><code>public class WidgetAlarmReceiver extends BroadcastReceiver{
  
  public static final String ACTION_REFRESH_ALARM =
          "WidgetAlarmReceiver.ACTION_REFRESH_ALARM";
  
  @Override
  public void onReceive(Context context, Intent intent) {
      WidgetActivity.startWidgetUpdateService(context);
  }
  }
  </code></pre>
  
  <p>BroadcastReceiver doesn't start that update service and I'm not sure why.</p>
  
  <p>edit: In manifest:</p>
  
  <pre><code>&lt;receiver android:name="WidgetAlarmReceiver"&gt;
          &lt;intent-filter&gt;
             &lt;action android:name="WidgetAlarmReceiver.ACTION_REFRESH_ALARM" /&gt;
          &lt;/intent-filter&gt;
  &lt;/receiver&gt;
  </code></pre>