title: Using TimerTask and Timer with Widget AppWidgetProvider
body: <p>I'm creating a clock widget using Android. I've tested the clock and the logic seems fine, but I need to get it to update every minute.</p>
  
  <p>I set the updatePeriodMillis to 60000 in my XML but Android limits this to 30 minutes, so it only updates every half hour.</p>
  
  <p>I did some research and a Service or AlarmManager might have worked except the method that I'm calling requires an AppWidgetManager and AppWidgetId that are passed to it via the onUpdate() method.</p>
  
  <p>I've tried two (similar) methods to get the minute update working:</p>
  
  <pre><code>static void updateAppWidget(final Context context, final AppWidgetManager appWidgetManager,
                              final int appWidgetId) {
  
      final Handler mHandler = new Handler();
      TimerTask minuteTask = new TimerTask() {
  
          @Override
          public void run() {
              mHandler.post(new Runnable() {
                  @Override
                  public void run() {
  
                      //Do Stuff
              });
          }
      };
  
      timer = new Timer();
  
      // schedule the task to run starting now and then every minute
      timer.scheduleAtFixedRate(minuteTask, 0l, 1000 * 60);
  
  }
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>static void updateAppWidget(final Context context, final AppWidgetManager appWidgetManager,
                              final int appWidgetId) {
  
      TimerTask minuteTask = new TimerTask() {
  
          @Override
          public void run() {
  
              //Do stuff
          }
      };
  
      timer = new Timer();
  
      // schedule the task to run starting now and then every minute
      timer.scheduleAtFixedRate(minuteTask, 0l, 1000 * 60);
  
  }
  </code></pre>
  
  <p>Any help is very much appreciated.</p>
  
  <p>Thanks.</p>
  
  <p>EDIT: In the time it's taken me to debug and make this post, I ended up leaving the app installed for half an hour. It would appear the timer has started after half an hour when onUpdate() was first called, but it still doesn't work for the initial 30 mins.</p>