title: Android Widget update
body: <p>Based on <a href="http://www.helloandroid.com/files/xmaswidget/android_howto-hellowidget.pdf" rel="nofollow noreferrer">this tutorial</a>  I created a widget that should show the time. The java way works, but the service way doesn't.</p>
  
  <p><strong>HelloWidget.java:</strong></p>
  
  <pre><code>public class HelloWidget extends AppWidgetProvider {
  
      @Override
      public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
  
          Intent intent = new Intent(context, UpdateService.class);
          context.startService(intent);
      }
  }
  </code></pre>
  
  <p><strong>UpdateService.java:</strong></p>
  
  <pre><code>public final class UpdateService extends Service {
      @Override
      public void onStart(Intent intent, int startId) {
          RemoteViews updateViews = new RemoteViews(this.getPackageName(), R.layout.main);
  
          Date date = new Date();
          java.text.DateFormat format = SimpleDateFormat.getTimeInstance(
                  SimpleDateFormat.MEDIUM, Locale.getDefault());
                  updateViews.setTextViewText(R.id.widget_textview, "Current Time " + format.format(date));
  
          ComponentName thisWidget = new ComponentName(this, HelloWidget.class);
          AppWidgetManager manager = AppWidgetManager.getInstance(this);
          manager.updateAppWidget(thisWidget, updateViews);
      }
  
      @Override
      public IBinder onBind(Intent intent) {
          // TODO Auto-generated method stub
          return null;
      }
  }
  </code></pre>
  
  <p>The <strong>hello_widget_provider.xml</strong> has this row: <code>android:updatePeriodMillis="1000"</code></p>
  
  <p><strong>Problem:</strong> </p>
  
  <p>The widget shows the current time but it's not updating (the java-way is).</p>
  
  <p>My main goal is to update the widget at e.g. 18:56 every day.
  Idk if this is the good way, but i tried to modify the onUpdate method like below, but it has a problem with ALARM_SERVICE: ALARM_SERVICE cannot be resolved to a variable</p>
  
  <pre><code>public class HelloWidget extends AppWidgetProvider {
  
      @Override
      public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
  
          AlarmManager alarmManager;
          Intent intent = new Intent(context, AlarmReceiver.class);
          PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0,
            intent, PendingIntent.FLAG_UPDATE_CURRENT);
          alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
          Calendar cal = Calendar.getInstance();
          cal.set(Calendar.HOUR_OF_DAY, 18);
          cal.set(Calendar.MINUTE, 56);
          cal.set(Calendar.SECOND, 0);
          cal.set(Calendar.MILLISECOND, 0);
          alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 86400, pendingIntent);
     }
  }
  </code></pre>
  
  <p>Any help is appreciated.</p>